Search code examples
androidhorizontalscrollview

android, scroll HorizontalScrollView to end in ListView


I'm using a right-to-left language in my ListView and because it's TextView may need more space, I used HorizontalScrollView. The text should be right align and when the user scrolls down, HorizontalScrollView should scroll to the rightest position (and as you know HorizontalScrollView is stuck in the leftest position at default). this is my ListView row code:

<HorizontalScrollView
            android:id="@+id/hs1"
            android:layout_width="0dp"
            android:paddingRight="5dp"
            android:layout_height="wrap_content"
            android:layout_weight="50" >

            <TextView
                android:id="@+id/txtProductName"
                style="@style/text_black"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="right|center_vertical"
                android:layout_gravity="right|center_vertical"
                android:textSize="@dimen/textsize" />
        </HorizontalScrollView>

and I use the code below in getView of my ListView Adapter for scrolling to right but it doesn't work:

new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    viewHolder.hs1.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
                    viewHolder.hs2.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
                }
            },500);

and at last, I used new Handler().post() too and not working.


Solution

  • Finally I found the solution, absolutely at my view when I wanted my HorizontalScrollView to show rtl (right-to-left) textView, The soluion is using RelativeLayout as parent .