我有一个 ListView,它在 View 的顶部包含一个 LinearLayout,用作标题栏。列表可以滚动,但标题栏保持不变。在标题栏中,我想要一个“后退”按钮,但这会导致标题文本变得不居中:
我添加了第二个相同大小的按钮(在标题栏的右侧)并使其不可见,以便充当文本居中的“分隔符”,但随后我松开了很多标题栏 -属性(property):
有没有办法告诉 Android 将标题文本居中并忽略后退按钮?也许这就是生活的方式,但我想我会先让每个人运行它,然后再使用一个笨拙的第二个、看不见的按钮或其他东西。 谢谢
最佳答案
你可以使用相对布局而不是线性布局,
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffaa" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:gravity="center"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:gravity="center"
android:paddingLeft="100dp"
android:paddingRight="100dp"
android:text="Header Title Embiggeden"
android:textSize="20dp" />
</RelativeLayout>
关于android - 如何使包含按钮的 Android 标题栏中的文本居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13970890/