这就是我所拥有的。我需要组数据中的那些粗体标题来换行,而不是右侧的数据。这是布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingRight="5dip"
android:paddingBottom="5dip"
android:paddingTop="5dip">
<TextView
android:id="@+id/igi_product"
android:textStyle="bold"
android:textSize="18sp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0">
<TableRow>
<TextView
android:id="@+id/igi_units"
android:gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TextView
android:id="@+id/igi_uom"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/igi_total"
android:gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/igi_price"
android:gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</TableRow>
</TableLayout>
</LinearLayout>
编辑:
我尝试用RelativeLayout替换LinearLayout,结果如下:
代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingRight="5dip"
android:paddingBottom="5dip"
android:paddingTop="5dip">
<TextView
android:id="@+id/igi_product"
android:textStyle="bold"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
<TableRow>
<TextView
android:id="@+id/igi_units"
android:gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TextView
android:id="@+id/igi_uom"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/igi_total"
android:gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/igi_price"
android:gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</TableRow>
</TableLayout>
</RelativeLayout>
最佳答案
出于这样的目的,我强烈推荐RelativeLayout
。
由于我在 LinearLayout
方面也遇到了很多(最微小的)问题,
RelativeLayout
对我来说非常有用。
好资源:http://www.mkyong.com/android/android-relativelayout-example/
否则:
尝试在困惑的 TextView 中使用 android:layout_width="fill_parent"
,或者给它一个权重属性 (android:layout_weight="1"
) 或尝试使用 android:minWidth="50dp"
...
也许其中之一适合您。
关于Android布局: left item in horizontal LinearLayout forces right justified text to jumble,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10934550/