跑马灯效果几年前好流行,一起在ListView 中解决过。但是很久没用了,一时竟然忘了。
其实在RecyclerView中解决方法也一样。
下面就权当做个记录。两个必要条件
1、XML配置
Textview 一定要用 android:singleLine="true"。因为这个方法过时了,就用 android:lines="1".怎么搞都没用。
<TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:lines="1" android:textSize="12dp" />
正确配置如下:
<TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:scrollHorizontally="true" android:textSize="12dp" />2、在adapter 里面 TextView 设置 holder.titleTv.setSelected(true);
@Override public void onBindViewHolder(MainListHolder holder, int position) { Uri uri = Uri.parse(Constant.IMG_BASEURL + mDatas.get(position).getMainPic()); Log.i("MainListAdapter", uri.toString()); holder.draweeView.setImageURI(uri); holder.titleTv.setText(mDatas.get(position).getTitle()); holder.titleTv.setSelected(true); holder.cityDsstrictTv.setText(mDatas.get(position).getCityTitle() + " [" + mDatas.get(position).getDistrictTitle()+"]"); holder.priceTv.setText(mDatas.get(position).getPrice() + ""); }