Reputation: 1015
I tried a lot for having scrolling text horizontally inside a listview.
i want one of my textview to scroll horizontally automatically like marquee
iam able to set horizontal scroll bar and scroll on touching it as
TVad.setMovementMethod(new ScrollingMovementMethod());
This is my xml file
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/tvinboxname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tvinboxmsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvinboxname"
android:maxLength="10"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tvtimeStamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/tvinboxmsg"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/tvadmsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvtimeStamp"
android:ellipsize="marquee"
android:focusableInTouchMode="true"
android:inputType="text"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:lines="1"
android:scrollHorizontally="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#330066" />
and in my getview method
// @Override
public View getView(final int position, View convertView,
ViewGroup parent) {
convertView = inflater.inflate(R.layout.inboxtextviews, null);
Tvname = (TextView) convertView.findViewById(R.id.tvinboxname);
Tvname.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(position)
.getname());
TVmsg = (TextView) convertView.findViewById(R.id.tvinboxmsg);
TVmsg.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(position)
.getmessage());
TVtimeStamp = (TextView) convertView.findViewById(R.id.tvtimeStamp);
TVtimeStamp.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(
position).getTimeStamp());
TVad= (TextView) convertView.findViewById(R.id.tvadmsg);
TVad.setText(VCAESInboxWithOutCheckboxes.Inboxlist.get(
position).getAd());
TVad.setSelected(true);
);
return convertView;
}
i searched a lot on this in stackoverflow and not able to display the scrolling text.
Upvotes: 3
Views: 4287
Reputation: 7605
Use custom class as shown below and
public class MyTextView extends TextView{
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
rotate();
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
rotate();
}
public MyTextView(Context context) {
super(context);
init();
rotate();
}
private void rotate() {
// TODO Auto-generated method stub
setSelected(true);
}
private void init() {
if (!isInEditMode()) {
}
}
}
add it in xml file for custome listview like shown below
<Your Package Name.MyTextView
android:layout_marginTop="10dip" android:id="@+id/tv_parse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="22px"
android:textColor="#34A4c5"
android:ellipsize="marquee"
android:maxWidth="220dp"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:layout_marginLeft="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginRight="10dp"></Your Package Name.MyTextView>
Upvotes: 6
Reputation: 192
For this you design your list view row from XML using SimpleListAdapter
.
Put a scrollview
in a row in XML.
<LinearLayout>
<scrollView>
<textview/>
</scrollView>
</LinearLayout>
Upvotes: 0
Reputation: 31
It you want the TextView to scroll horizontally while list is IDLE you need to set the TextView to selected state.
public void bindView....
// Assuming you have a static view holder class
viewHolder.myTextViewToScroll.setSelected(true);
Now it should scroll :)
Upvotes: 3