我有一个相当简单的布局麻烦斑点。那就是:布局麻烦
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/id1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="end"
android:maxLines="1"/>
<TextView
android:id="@+id/id2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
3个问题:
如何中心垂直两个TextViews(也许还好说,这些观点中的文本)母公司的LinearLayout内?左视图垂直居中确定,但正确的(因为它具有较小的字体)不是。它似乎在顶部垂直居中。我显然尝试玩第二种视图的layout_gravity,但这没有任何区别。我能解决这个问题的唯一方法是将第二个TextView放在一个LinearLayout中,并将其布局高度参数设置为match_parent(但这是否是正确的方式?)
同样,我希望左侧的视图水平居中在左侧,右侧的视图水平居中在右侧。目前右侧视图立即放置在左侧旁边。我可以解决这个问题的唯一方法是将这样的插图中的两个文本观点:
<TextView android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" android:text="">
基本上作为它的大小取决于文本的legth两个TextViews减少间隔
如果视图的组合文本不能水平放置,我希望左侧视图中的文本被截断。没有包装到新的生产线上。目前,左侧视图中的文字只是将“正确”的文字从父文件中“推出”。不知道如何实现这一点(除了添加
android:maxLines="1"
来阻止文本换行)。我试过android:ellipsize="end"
但这似乎没有任何影响。
在线性布局中设置android:gravity =“center_vertical”。 –
谢谢。这回答了第一部分! – Lieuwe