个人小记--一些简单的知识点

一. textview 滚动显示

      当TextView需要显示文字过多的时候,可以选择滚动显示,在.xml文件中添加属性

  android:scrollbars="vertical"
  然后在使用的时候
  import android.text.method.ScrollingMovementMethod;

  tv.setMovementMethod(ScrollingMovementMethod.getInstance());


   当文字过多,但是不想全部展示的时候,可以在.xml文件中添加属性
  android:ellipsize="end"//表示省略号出现在文字末尾
  android:maxLines="2"//显示的最多行数

二. Switch控件的使用
    Switch控件是安卓提供的开关按钮,用法跟button很相似
    首先我们先看一下布局文件
    
    <Switch
    android:id="@+id/switch1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:switchMinWidth="90dp"
    android:textOff=""
    android:textOn=""
    android:thumb="@color/colorAccent"
    android:track="@drawable/switch_selector" />
    thumb 文字所携带的背景,设置为背景色进行隐藏。不设置会出现原生的背景条。
    这个我自己定义了背景图片(track),
    以下是switch_selector的内容

    <item android:drawable="@drawable/btn_green" android:state_checked="true"></item>
    <item android:drawable="@drawable/btn_close" android:state_checked="false"></item>
    然后在状态改变的时候作相应的处理
    switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
         if(isChecked){
             //打开
         }else{
            //关闭
         }
    }
   });


   
     

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值