Android 如何使TableRow从右向左
如何将视图从右向左添加到Android 如何使TableRow从右向左,android,right-to-left,android-tablelayout,tablerow,Android,Right To Left,Android Tablelayout,Tablerow,如何将视图从右向左添加到表格行?默认模式为从左到右。我尝试了android:gravity=“right”和android:layout\u gravity=“right”在TableLayout和TableRow中,但都没有成功。 例如: <TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="wrap_conten
表格行
?默认模式为从左到右。我尝试了android:gravity=“right”
和android:layout\u gravity=“right”
在TableLayout
和TableRow
中,但都没有成功。
例如:
<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>
结果是按钮1在左边,文本视图1在右边,但我需要反之亦然。您的答案很简单。与任何表格一样,您选择的第一个条目将首先显示,在您的示例button1中,您需要将其设置为TextView,以便将其放置在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>
请发布您的XML代码,我可以提供帮助。我正在动态地这样做。您的意思是在Java中实用吗?是的,但没关系,XML和动态类型都不能处理RTL添加视图。这是我的问题,我该怎么做?理想情况下,你不能选择其中一个。当您以实用方式和XML方式创建视图时,它们可能会相互冲突,因此会产生问题。你真的需要发布代码,否则你不会得到答案。你完全误解了我的问题。“第一”在哪里?右还是左?:)默认值是LTR,我需要RTL dude。我告诉过你,我是动态地这样做的,这个XML只是一个例子如果你检查我提供的XML,然后按钮1出现在右边,文本现在在左边,正如你所说的那样?:|我不想改变添加视图的顺序,伙计!考虑到我有一个从索引0到n的视图数组,我想在TabLeRoW的右边添加View(0),而不是查看[N]。如果你不发布正确的源代码,你将永远不会得到答案,这不仅仅是我,这里的任何人都会如此。我很清楚,对不起,我没有答案,我在寻找同样的东西
ViewCompat.setLayoutDirection(tableRow,ViewCompat.LAYOUT_DIRECTION_RTL);