Horizontal scrollable Textview not working - android

This is the xml file for scroll the textview,but it is not working.
<TextView
android:id="#+id/txt_join_crew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:paddingEnd="5dp"
android:paddingRight="5dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="#string/join_my_crew"
android:textSize="#dimen/content_text_size" >
</TextView>
this is the xml code and it is not working.

You code work but you have add this code in java
TextView tv=(TextView)findViewById(R.id.txt_join_crew);
tv.setSelected(true);

Related

Ellipsized TextView in ListView item not working

I've got an xml file for a ListView item. it looks like this, containing three textviews:
Now, the second TextView in the middle sometimes got text that is too long to fit between the other two TextViews. That's why I wanted to make it ellipsized.
My .xml file looks like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="2dp"
android:background="#drawable/card_background" >
<TextView
android:id="#+id/list_textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="#string/test"
android:textColor="#color/text"
android:textSize="20sp"
android:textStyle="bold"
android:width="75dp" />
<TextView
android:id="#+id/list_textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:layout_toRightOf="#+id/list_textview1"
android:layout_toLeftOf="#+id/list_textview3"
android:text="#string/test"
android:textColor="#color/text"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/list_textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingLeft="20dp"
android:paddingRight="5dp"
android:text="#string/test"
android:textColor="#DEDEDE"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
As You might see in the center TextView values, I've added
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
But the result is just a long text, shorten with three points at the end. It just won't move?
Here's an image:
This center TextView does not scroll.
Note that it's an item of a ListView. That's why I tried to made the center TextView focusable, what ended in not being able to press on the list item.
Any ideas?
I've got the solution from user zgc7009 :
I just had to add:
TextView textView3 = (TextView) findViewById(R.id.list_textview3);
textView3.setSelected(true);
Worked nicely, thanks!

Android App Widget - How To Create TextView Marquee On Two Separate Lines With Adjustable Scrolling Speeds?

I'm trying to create a widget with several different lines on it and want to set it to auto scroll (marquee) and have the ability to adjust the scrolling speed. How can I accomplish this?
I tried using a TextView and was able to make it scroll on one line, but that's it. I can't seem to adjust the speed of it or have two lines scrolling at the same time.
An example of this is: https://play.google.com/store/apps/details?id=huntsman.stocktickertapelite&hl=en
OR
https://play.google.com/store/apps/details?id=com.cousinHub.widget
Anyone have an idea of how they did it? (custom views?)
Thanks.
This is what I have so far:
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textStyle="bold"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/app_name"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true"
android:layout_weight="1">
<requestFocus
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true" />
</TextView>
Try this, I am getting the text from Java as setText file, and show in this screen
<ScrollView
android:id="#+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/line_dotted"
android:layout_marginBottom="10dp"
android:fillViewport="true"
android:scrollbars="vertical" >
<TextView
android:id="#+id/text_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15sp"
android:layout_marginRight="15sp"
android:layout_marginTop="10sp"
android:scrollbars="vertical"
android:textColor="#0A2A1B"
android:textSize="12sp" />
</ScrollView>
Or You can try this without scrollview, the text will scroll when there is more than 5 ines
<EditText
android:id="#+id/Comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/Submitbtn"
android:layout_alignParentLeft="true"
android:layout_below="#+id/ratingBar"
android:layout_marginBottom="40dp"
android:ems="10"
android:gravity="left"
android:hint="Comments"
android:maxLines="5"
android:padding="20dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:imeOptions="actionDone" />

Android: ViewFlipper resetting my marquee TextView

My app contains a ViewFlipper and in the same activity, a marquee text inside a TextView.
The TextView is NOT inside the ViewFlipper. The ViewFlipper is filled programatically later.
When the Viewflipper transition occurs, the marquee text resets, returning to initial position...
Anyone knows why do this happen?
How can I fix that?
//VIEWFLIPPER
<ViewFlipper
android:id="#+id/vfHome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:flipInterval="5000" >
</ViewFlipper>
//...
//MARQUEE TEXT
<TextView
android:id="#+id/tvHome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_vertical"
android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:paddingTop="2dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollHorizontally="true"
android:scrollbars="horizontal"
android:singleLine="true"
android:text=""
android:textColor="#EEE"
android:textSize="13dp" >
</TextView>
Thanks

how to make a textview marquee inside a focussed layout in android

I am doing an application in which I have a textview and an image view inside a LinearLayout. Touching the linear layout takes us to another activity. As the text wont fit inside the textview, I want to make the textview content marquee. I have tried may methods but it is not working. The xml content is given below.
<LinearLayout
android:id="#+id/profile_pic_Layout"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:layout_margin="10dip"
android:background="#color/blue_background" >
<ImageView
android:id="#+id/profile_pic_menu"
android:layout_width="100dip"
android:layout_height="100dip"
android:contentDescription="#string/image"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/profile_name_text"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:layout_gravity="bottom"
android:gravity="center"
android:marqueeRepeatLimit="1"
android:inputType="text"
android:lines="1"
android:duplicateParentState="true"
android:scrollHorizontally="true"
android:fadingEdge="horizontal"
android:focusable="true"
android:textColor="#android:color/white"
android:textSize="20sp">
<requestFocus android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true" />
</TextView>
</LinearLayout>
I have also tried setting the textview selected in the code by using,
profileNameTextView.setEllipsize(TruncateAt.MARQUEE);
profileNameTextView.setSelected(true);
I think the it is because, the the parent linearlayout is having the focus.
Please help me fix this issue..!
Thank you all in advance..!
Apparently you are missing the android:ellipsize="marquee" attribute
Here's a minimalistic working example:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:marqueeRepeatLimit="1"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="HELLO HOW ARE YOU WHAT ARE YOU DOING TEST ANDROID IS WRITING TO YOU." />
public class TextViewMarquee extends Activity {
private TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) this.findViewById(R.id.mywidget);
tv.setSelected(true); // Set focus to the textview
}
}
The xml file with the textview:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/mywidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use marquee, with a long text" />

marquee text view animation

The marquee animation does not work, this is what I did.
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content" android:background="#drawable/bg_trans"
android:layout_alignParentBottom="true" android:orientation="vertical">
<TextView android:id="#+id/trackName"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:textColor="#android:color/white" android:textSize="18sp"
android:maxLines="2" android:ellipsize="marquee"
android:scrollHorizontally="true"
android:focusable="true" android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:layout_gravity="center_horizontal" />
<TextView android:id="#+id/artistName"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:textColor="#android:color/white" android:textSize="18sp"
android:maxLines="2" android:ellipsize="marquee"
android:scrollHorizontally="true"
android:focusable="true" android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:layout_gravity="center_horizontal" />
</LinearLayout>
It works for the first textview but doens't work for the second. What am I doing wrong?
This works for me -
<TextView
android:id="#+id/capture_mode"
android:layout_width="200px"
android:layout_height="wrap_content"
android:text="This is a test of marquee on the text view in android."
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
/>
The field marqueeRepeatLimit will set the number of repitions.
UPDATE: The width of the text view need to be hardcoded to a specific value, you can set it to wrap_content. In such cases the marquee will still work just that it will have some blank space after the end the text and before it starts to display the text again. (Think Digital signboards, they have some gap in the display before displaying the next item.)
Other then what is mentioned above you also need to add
txtView.setSelected(true)
worked for me adding this line

Categories

Resources