ViewCompat.setLayoutDirection(tableRow,ViewCompat.LAYOUT_DIRECTION_RTL);
How to make TableRow right-to-left
-
14-07-2023 - |
Question
How can I add views to TableRow
right-to-left? the default mode is left-to-right. I tried android:gravity="right"
and android:layout_gravity="right"
inside both TableLayout
and TableRow
but didn't work.
for example:
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:layoutDirection="rtl"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:layoutDirection="rtl">
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text" />
</TableRow>
</TableLayout>
the result is button1 at the left and textView1 at the right but I need vice versa .
Solution
OTHER TIPS
Your answer is simple. As with any table the first entry you chose will appear first, in your case button1, you need this to be TextView for it to be placed before the button1.
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:layoutDirection="rtl"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:layoutDirection="rtl">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text" />
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
</TableLayout>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow