Android-通过TextView控件实现跑马灯效果

    科技2022-09-01  105

    TextView实现跑马灯效果

    xml文件中声明属性,使TextView获取焦点 核心属性:singleLine,ellipsize,focusable,focusableInTouchMode <TextView android:id="@+id/text_marquee" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:text="跑马灯文字跑马灯文字跑马灯文字跑马灯文字跑马灯文字跑马灯文字"/>

    2.acticity中加入如下代码

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_text); //跑马灯效果 TextView tv = findViewById(R.id.text_marquee); tv.setSelected(true); }
    Processed: 0.008, SQL: 9