【发布时间】:2011-04-26 23:35:12
【问题描述】:
我无法让两个 Textview 以我想要的方式运行。
我想要一个在左边,另一个在右边。我相当简单地通过水平线性布局实现了这一点。如果字符串太长,他们都应该只使用一半的水平空间(“留在他们身边”)并垂直扩展。
但是,如果一个或两个文本视图包含很长的字符串,我会得到奇怪的结果,具体取决于我设置权重的方式。
例如如果我将权重设置为 Left=1,Right=1 如果两个字符串都很短或两个字符串都很长,则一切正常。但是,如果它们不同,则短的将缩小为仅在每行字符上显示。使用 0/0 权重,较短的 TextView 就完全消失了。
如果我将短字符串文本视图设置为“0”,将长字符串文本视图设置为“1”或更高,我可以让它工作,但这仅涵盖一种情况。
我也尝试过 TableLayout 和 RelativeLayout,但没有任何效果。
亲切的问候, 水母
编辑: 通过将 TextViews 放入水平布局内的垂直 LinearLayouts 来解决它:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_gravity="right">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_gravity="right">
</TextView>
</LinearLayout>
</LinearLayout>
虽然对我来说似乎有点过大......但显然没有其他解决方案?
【问题讨论】: