一. 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{ //关闭 } } });