Android: how to display several areas at the same time (focus for two tents)

I want 2 marquee in my application. But only one always works. If I comment on the first, then the second will work. Otherwise, the first. Or only one tent gets focus at a time. If we press the down arrow, the second will begin to focus. How can both of these tents focus?

How can I display 2 brown hairs at the same time? Below is my code:

<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/imgLogotb"> <TextView android:id="@+id/txt1" android:layout_width="wrap_content" android:text="START | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | END" android:layout_height="20dip" android:singleLine="false" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:focusable="true" android:focusableInTouchMode="true" android:freezesText="true"> </TextView> <TextView android:id="@+id/txt2" android:layout_width="wrap_content" android:text="START | lunch 1.00 | Dinner 2.00 | Travel 3.00 | Doctor 4.00 | lunch 5.00 | Dinner 6.00 | Travel 7.00 | Doctor 8.00 | END" android:layout_height="20dip" android:singleLine="false" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:focusable="true" android:focusableInTouchMode="true" android:freezesText="true"> </TextView> </RelativeLayout> 

Please help me by giving a solution. Thanks...

+4
source share
1 answer

I usually do not answer old questions. But in this case, I ran into the same problem, and it was an interesting situation.

Now I have found a patch, one might say, for myself. Marquee text works when it is in focus. Now our goal is to focus on each text screen at the same time.

To do this, we will create our own native component of the TextView component. and will always return true in the isFocusable () method. Here he goes .....

 public class ScrollingTextView extends TextView { @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if(focused) super.onFocusChanged(focused, direction, previouslyFocusedRect); } @Override public void onWindowFocusChanged(boolean focused) { if(focused) super.onWindowFocusChanged(focused); } @Override public boolean isFocused() { return true; } } 

now all you have to do is add this text to your xml layout as follows.

 android:text="LONG LONG LONG LONG text..................." android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:id="@+id/TextView03" android:padding="5dip" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 

and its execution, you can add this TextView component as many times as you want in the xml layout. and all text will be highlighted at the same time.

Thanks.

+4
source

Source: https://habr.com/ru/post/1332751/


All Articles