【发布时间】:2014-02-14 23:10:34
【问题描述】:
我试图在我的文本视图中居中一些代码,但它似乎一直保持左对齐:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_above="@+id/myButtons">
<!-- Text -->
<TextView
android:id="@+id/myText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="22sp"
android:text="Test"
android:textStyle="bold" />
<!-- And the thumbnail -->
<ImageView
android:id="@+id/image"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/image_text"
android:layout_gravity="center" />
</LinearLayout>
图像(如果有,有时会设置为 Visibility.GONE)居中对齐。只是我无法让文本居中对齐。
欢迎任何想法。谢谢!
【问题讨论】:
-
你试过我的答案了吗?
-
是的,我在你的回答下回复了:)
-
我已经编辑了我的答案看看
-
LayoutParams.FILL_PARENT 根据 Eclipse 已被弃用。仍然可以安全使用吗?
-
更改为 LayoutParams.MATCH_PARENT
标签: alignment android-linearlayout textview android