android控件的深入使用
来源:互联网 发布:网络四大名著之首 编辑:程序博客网 时间:2024/06/06 01:45
一)TextView的跑马灯效果
1)对于单个的TextView实现跑马灯很简单,只需要给控件设置如下属性
android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true"
2)当有多个控件都需要获取焦点,焦点会被第一个控件拿到,因此在此例中,两个textview在相同的属性设置情况下,只有第一个textview可以实现跑马灯,那么如何让所有的textview都实现获取焦点呢?答案是通过自定义textview
public class Mytextview extends TextView {public Mytextview(Context context) {super(context);// TODO Auto-generated constructor stub}public Mytextview(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {super(context, attrs, defStyleAttr, defStyleRes);// TODO Auto-generated constructor stub}public Mytextview(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);// TODO Auto-generated constructor stub}public Mytextview(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}@Overridepublic boolean isFocused() {return true; }}
然后在引用控件的时候需要引用我们自定义的textview
<com.example.paomadeng.Mytextview android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" /> <com.example.paomadeng.Mytextview android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:layout_marginTop="10sp" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" />
二)AutoCompleteTextView的使用
1)引用控件
<AutoCompleteTextView android:id="@+id/tv1" android:layout_width="match_parent" android:layout_height="wrap_content" />2)在代码里创建相应的适配器
public class MainActivity extends Activity {private AutoCompleteTextView auto;private MultiAutoCompleteTextView Mulauto;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);auto = (AutoCompleteTextView) findViewById(R.id.tv1);String data[] = new String[] { "淮北", "淮北人民网", "淮北师范大学", "Google", "Google Map", "Google Mails" };ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_dropdown_item_1line, data);// 第二个参数表示适配器的下拉风格auto.setAdapter(adapter);
3)多个输入匹配
<MultiAutoCompleteTextView android:id="@+id/tv2" android:layout_width="match_parent" android:layout_height="wrap_content" />在代码里
Mulauto = (MultiAutoCompleteTextView) findViewById(R.id.tv2);Mulauto.setAdapter(adapter);Mulauto.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());// 完成对选项的拆分的功能,以逗号进行拆分
0 0
- android控件的深入使用
- Android一些控件的使用
- android Tabhost控件的使用
- android include控件的使用
- android Tabhost控件的使用
- android shape控件的使用
- android 控件的使用 备注
- Android常使用的控件
- Android Button控件的使用
- android AutoCompleteTextView控件的使用
- android Chronometer控件的使用
- Android ListView控件的使用
- Android控件RatingBar的使用
- android webiew 控件的使用
- Android ViewPager控件的使用
- Android RadioGroup控件的使用
- Android::RatingBar控件的使用
- Android::SeekBar控件的使用
- Kafka入门经典(官网翻译)
- memcpy
- CSS优先级
- storm流程——kafka
- 20160611
- android控件的深入使用
- LeetCode-75.Sort Colors
- 欢迎使用CSDN-markdown编辑器
- [转] Python 2.7.x 和 3.x 版本的重要区别小结
- Spring AOP初探(二)
- 函数重载(最高层有多个匹配函数找到,调用将被拒绝)
- Solving state function of continuous-time LTI system
- 让你痛苦的5个心理陷阱
- 笔试模拟题 中兴---单词接龙