Android – reverse checkbox for textview

I tried different ways to reverse the textview box in Android. I use this "link" to do this

But it doesn't work for me! What's wrong with my code? It's my only way. I don't want animation solutions to lead to screen restrictions

XML:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/a"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/hScroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal" >

    <LinearLayout
        android:id="@+id/lyr"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/tv"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="test for reverse marqueee a.test for reverse marqueee b.test for reverse marqueee c." />
    </LinearLayout>

</ScrollView>

</LinearLayout>

JAVA:

public class TextmovingActivity extends Activity {

      private Integer scroll_pos;
      Handler         hHandler;
      TextView        tv;
      LinearLayout    hsView;
      ScrollView      hScroll;



      @Override
      public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                tv = (TextView) findViewById(R.id.tv);

                hScroll = (ScrollView) findViewById(R.id.hScroll);
                tv.setSelected(true);
                hHandler = new Handler()
                {

                          @Override
                          public void handleMessage(Message msg)
                          {
                                    scroll_pos = (int) tv.getLayout().getLineWidth(0);
                                    hScroll.scrollTo(scroll_pos, 0);
                                    scroll_pos--;
                                    if (scroll_pos >= 0)
                                              hHandler.sendEmptyMessage(0);
                          }
                };
      }
  }

resolvent:

This solution applies to RTL languages (Arabic, Persian,...):

Simply add this property to textview:

android:textDirection="rtl"

For 17 the following APIs, add this property to textview:

android:gravity="right"

(it's not suitable for simulators, but it works perfectly with real phones.)

Examlpe:

XML:

    <TextView
    android:id="@+id/txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:text="write something in Arabic,Persian,... here"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:singleLine="true"
    />

JAVA:

TextView txt = (TextView) findViewById(R.id.txt);
txt.setSelected(true);

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>