Q
左右对齐
1
A
回答
3
您可以根据您的要求使用以下布局::
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#ffffff" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:layout_alignParentRight="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:layout_alignParentRight="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>
0
您可以使用RelativeLayouts。然后,只需定位像
android:layout_alignParentRight="true"
您textviews这里是链接这种类型的布局:
0
你可以把整个视图到一个RelativeLayout的,并使用layout_alignParentLeft,layout_alignParentRight坚持的TextView到视图的左侧和右侧,然后layout_alignBaseline保留每个侧面的Textview。然后layout_below放置下一行Textview。
或者,您可以使用LinearLayout来layout_width =“match_parent”,然后使用上面的相同方法将红框变为RelativeLayout。
但是,我建议您检查每个布局的类型以查看每个容器的特性,然后决定哪个最适合您的视图作为整体,但请记住,屏幕上的视图/布局越多影响某些设备的性能。 :)
0
您可以使用RelativeLayout,但同一行中这两个视图的一个视图应该具有某个固定的宽度。如果你确定右视图的宽度不会超过某个宽度,那么你也可以将wrap_content分配给宽度,但如果第二个视图可能占用全屏宽度,那么它必须为布局分配一些固定的宽度。
所以集合的LayoutParams到左和右视图如下: LeftView:
Layout_width = FILL_PARENT,Layout_height = WRAP_CONTENT,layout_toLeftOf = @ + ID/rightView,
SecondVIew:
Layout_width = wrap_content,Layout_height = wrap_content,layout_alignParentRight = true
1
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#ffffff" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:layout_alignParentRight="true"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:layout_below="@+id/textView1"/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:layout_alignParentRight="true"
android:layout_below="@+id/textView2"/>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:layout_alignParentLeft="true"
android:layout_below="@+id/textView3"/>
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:layout_alignParentRight="true"
android:layout_below="@+id/textView4"/>
</RelativeLayout>
相关问题
- 1. 左右对齐
- 2. css/html左对齐和右对齐href
- 3. HTML左对齐,右对齐不工作
- 4. 右对齐和左对齐UITextView。
- 5. 对齐左/中/右LinearLayout - Android
- 6. iPhone - UITableView左右对齐
- 7. 左右对齐消息
- 8. Gnuplot左右对齐字幕
- 9. 左右对齐richtextbox c#
- 10. HTML左,右对齐元素
- 11. NSString左右对齐文本?
- 12. 垂直对齐左右div
- 13. 从右至左对齐UITableView
- 14. 左侧的接合部右对齐左对齐场场水晶
- 15. 如何将右对齐或左对齐与“\ t”对齐?
- 16. 物品对齐从右向左而不是从左向右
- 17. 在PHPWord中,左右对齐词
- 18. HTML表格对齐左右逢源
- 19. Android如何对齐文本左右editText
- 20. IE 7左中右对齐无表
- 21. 如何对齐QHBoxLayout,负责左,中,右
- 22. Silverlight:左右对齐ItemTemplate中的元素?
- 23. 文本左对齐,右一个按钮
- 24. 对齐divs左右彼此相邻
- 25. 将UITabBarItem图像向左右对齐
- 26. 左右对齐消息气泡
- 27. 对齐中心div的左右div div
- 28. CSS3 - 动画文本对齐左/中/右
- 29. Listview中的左右对齐行?
- 30. Bootstrap左右分区块对齐
这只有在对于每一行左边和右边的'TextView'高度相同的情况下才有效。 – tir38 2014-06-07 01:15:36