How to add right-to-left views to HorizontalScrollView?

I have a horizontalscrollview with a LinearLayout inside, I am adding some views to the linear layout, the views are buttons! but the thing is, they add to linear layout from left to right, I want them to add from right to left, how can I achieve this?

this is my layout:

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/filteringSearchBox"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:layoutDirection="rtl" >

    <LinearLayout
        android:id="@+id/filteringHeaderLL"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:gravity="end"
        android:layoutDirection="rtl"
        android:orientation="horizontal" >
    </LinearLayout>

</HorizontalScrollView>

      

I have been playing with layout and gravity, none of them work please give me a complete answer

this is the code:

    for (int i = 0; i < mFilteringWB.length; i++) {
        Button mButton = new Button(mContext);
        mButton.setId(i);
        mButton.setTextColor(Color.parseColor("#6D6D6D"));
        mButton.setTextSize(13);
        mButton.setBackgroundResource(R.drawable.shad_filtering);
        mButton.setTypeface(mFace);
        mButton.setText(mFilteringWB[i]);
        mLayout.addView(mButton);
    }

      

+3


source to share


1 answer


Use addView (View Child, int index) instead of void addView (View Child)



mylinearLayout.add(myButton, 0); // add new views to index 0 which is left

      

+1


source







All Articles