<TextView
android:id="@+id/item1_title_message"
android:layout_width="160dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dip"
//设置当文字过长时,该控件该如何显示。有如下值设置:”start”—?省略号显示在开头;”end” ——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_vertical"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="好消息:今天是2015年的第一天,大碗干拌祝大家新年快乐"
文字滚动效果会自动运行
如果需要点击滚动 需要处理焦点
<LinearLayout android:layout_width="fill_parent"
android:layout_height="100dip"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
/>
<TextView
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="走马灯效果的演示"
android:singleLine="true"
android:ellipsize="marquee"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
></TextView>
</LinearLayout>
走马灯效果消失,说明焦点转移到代码中的第二个LinearLayout。
,在触摸模式下android:clickable="true"是(android:focusable="true",android:focusableInTouchMode="true")能获得焦点的必要条件,
就是说一个控件想要在触摸模式下获得焦点就一定要可点击,上面三个属性都要有。