您的位置:首页 > 移动开发 > Android开发

android:TextView相关使用问题

2016-09-28 12:19 423 查看
1、TextView的Layout属性:

      wrap_content:包裹实际文本内容;

      match_parent:当前控件铺满父类容器,2.3API之后

      fill_parent:当前控件铺满父类容器,2.3API之前

2>、TextView的跑马灯效果实现

   1、实现4个属性:

       android:singleLine = "true"

        android:ellipsize="marquee"

        android:focusable="true"

        android:focusableInTouchMode="true"

     2、创建一个继承TextView的子类

      //添加构造函数 Source --> Generate Constructors from Superclass

     public class MarqueeText extends TextView {

          public MarqueeText(Context context, AttributeSet attrs, int defStyle) {

               super(context, attrs, defStyle);

               // TODO Auto-generated constructor stub

           }

         public MarqueeText(Context context, AttributeSet attrs) {

                  super(context, attrs);

                  // TODO Auto-generated constructor stub

           }

         public MarqueeText(Context context) {

              super(context);

              // TODO Auto-generated constructor stub

          }

        @Override

         public boolean isFocused() {

           return true;

         }

   4、修改TextView的引用:<com.example.textview.MarqueeTex

2>、AutoCompleteTextView实现自动匹配输入内容 

         //第一步:初始化控件

        //第二步:需要一个适配器

        //第三步:初始化数据源  -- 这数据源去匹配文本框中的数据

        //第四步:讲adpter与当前autoCompleteTextView进行绑定

        acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,

                android.R.layout.simple_list_item_1, res);

        acTextView.setAdapter(adapter);

        private AutoCompleteTextView acTextView;

        private String[] res = {"beijing1", "beijing2", "beijing3", "shanghai"};

          android:completionThreshold="3" //输入几个开始自动匹配

3>、 MultiAutoCompleteTextView  可支持选择多个值得匹配,分别用分隔符分开,比如输入邮件

        独特属性:设置分隔符的样式  mtxt.setTokenizer(new MultiAutoCompleteTextView.Commatokenizer());

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  TextView