TextView marquee WITHOUT android:layout_width="match_parent" - android

I am making a UI which will look like this
My goal is to add marquee scroll effect in highlighted text views, The parent container for the both text view is Constraint layout, Hence I am using android:layout_width="0dp" so that my view expands to its constraints that is 50-50 of the total space.
I did some research and found that I need android:layout_width="match_parent" in order to achieve marque.
My current code for marquee:
<TextView
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:singleLine="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:scrollHorizontally="true"
android:gravity="start"
android:id="#+id/row_load_list_toAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="End Location"
android:textColor="#color/black"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView5"
app:layout_constraintTop_toBottomOf="#+id/textView13" />
Anyone please put a light on what I might be doing wrong here and what is the solution?

Inorder for the marquee to work you must set setSelected property to true in your Activity related to that layout
TextView txt = findViewById(R.id.row_load_list_toAddress);
txt.setSelected(true);
Hope this will fix your problem.

Related

Android Horizontal View Edit Text Input Type

I have a horizontal scroll view and, in an item of this scroll view I have an edit text. Its gravity set as center. If I don't set any input type it works well and also if I set gravity of edit text to left and set input type to any type it works well, but when I set any input type with gravity center it scrolls to last element of horizontal view ? Can anyone help me ?
Thanks in advance.
Both of them is a part of scroll view. First one works well whereas second one is not.
For note: they are not in same xml, I did to just show you to both.
<EditText
android:id="#+id/NameOfToDo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="192"
android:textColor="#color/white"
android:textSize="20dp"
android:maxLines="1"
android:focusableInTouchMode="true"
android:inputType="text"
android:ellipsize="end"
android:gravity="left"
android:textCursorDrawable="#null"
android:background="#00000000" />
<EditText
android:id="#+id/NameOfToDo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="192"
android:textColor="#color/white"
android:textSize="20dp"
android:text="Kişisel Gelişim"
android:maxLines="1"
android:focusableInTouchMode="true"
android:inputType="text"
android:ellipsize="end"
android:gravity="center"
android:textCursorDrawable="#null"
android:background="#00000000" />
Try removing the layout weights and set the width of each item in the scrollview in some other way. Layout weights in scrollviews are invalid.

Text Animation in android

I want to animate the text of the textview not the whole textview in Android application. I am currently using Marquee property of Android textview but it is not 100% what i want, so i want to animate the text inside the textView so i can handle the events also. If someone with work around on this, please share your answers.
thanks
Here is what i have done at the moment using Marquee
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="bottom"
android:maxLines="1"
android:scrollbars="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Hello World"
android:textColor="#FFFFFF"
android:textSize="24sp"/>

Multiline TextView with width "wrap_content"

I am wondering how to have a TextView display its content on several lines without hardcoding the width in the XML.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="Long multiline text"/>
<TextView
android:textColor="#color/text_color"
android:layout_width="130dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
Any thought welcome.
EDIT: my problem is that when the text exceeds the width set (because it reaches the end of the screen) a portion of the text is just not displayed. I would expect the text to be split on two lines
Though I cannot reproduce the not wrapping problem, you can fix the positioning problem by using a weight on the first TextView. Using the following XML gives the expected output in the graphical layout view in Eclipse:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="Long multiline text"/>
<TextView
android:textColor="#color/text_color"
android:layout_width="130dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
Also add
android:minLines="2"
android:scrollHorizontally="false"
You could try
android:inputType="textMultiLine"
in your TextView XML. This worked for me.
I think I had very similar problem. I had a TextView with a text, where I was not sure how much lines will it take. It was encapsulated by a LinearLayout having android:layout_width="match_parent" to ensure my text will fill out all the space horizontally. However, the problem was that my text did not fit into 1 line and when it did break into a new line, the next view component below it did not move downwards to give enough space for the second line to be viewable fully.
I could achieve the solution by changing the LinearLayout that was containing my TextView into a RelativeLayout. By this way, the element below the text (actually below the Layout itself) was moved automatically to give enough space for the multi-line text.

Smooth horizontal scrolling text

I understand that this might be a duplicate, but I havent found an answer.....yet!
How can I make a smooth horizontal scrolling text in my Android-app? I want the text to scroll like a stockticker on the TV-news. I also need a callback when the scrolling is completed so i can set a new text to scroll.
What is the best way to do this?
Thanks!
Good Question.
First of all to do this, place following code in your layout file for TextView
android:ellipsize="marquee"
android:focusable="false"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
Then write following code in your code file,
TextView txt = (TextView) findViewById(R.id.textView);
txt.setSelected(true);
You must give setSelected(true) to make textview scroll automatically.
Thanks.
For Manually Scrolling
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="40dp"
android:layout_height="wrap_content"
android:scrollHorizontally="true"
android:text="Horizontal scroll view is working"/>
</HorizontalScrollView>
For Automatic Scrolling
<TextView
android:text="Single-line text view that scrolls automatically if the text is too long to fit "
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

Scroll a text automatically on horizontal

I want to scroll a text automatically in horizontal way. I tried the method below, but the text was not scrolling.
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/bg_1"
android:textColor="#cc0000"
android:scrollHorizontally="true"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
/>
So please tell me how to scroll a text and if there is any need to add some code in the class file also.
your TextView don´t scroll because their with must be fill_parent, and the other thing is that the textview must be selected (not pressed) to scroll.
Also, beside what Franco told you, you have set android:ellipsize="marquee"(that truncate the text to fit on that single line you have set), so probably that mix up with the scrolling you set by android:scrollHorizontally="true"
My suggestion is to try to remove the ellipsize property.
i put a listview in above textview so the textview is not scrolling. so itried this one
set listview focusable is false
listview.setfocusable(false);
then it works the text was scrolling.
Try this....
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="John Jonathan Samuwell Abbruzzi"
android:singleLine="true"
android:scrollHorizontally="true"
android:textSize="50sp" />
</HorizontalScrollView>

Categories

Resources