【发布时间】:2015-02-03 14:31:52
【问题描述】:
我在 LinearLayout 中有一个 textView,它显示的文本并不总是在中心,即使我使用重力 =“center”属性。我还用“match_parent”设置了 layout_width。
此 textView 位于 LinearLayout 中,该 LinearLayout 位于视图的父 LinearLayout 中。
我的 textView 在 ListView 中,代表项目行的结尾。
我的适配器使用 ViewHolder 模式。
这里我真的不明白为什么有时文字居中而有时居左。
这是我的视图的 2 个屏幕截图,其中您可以看到对齐问题的不同状态:
我想要的: 这里只是关于文本现在或显示在此位置的时间,我想仅在中心显示此文本,有时它显示在左侧,如您在上面的屏幕截图中所见。
ListView 布局:
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/dialogTitle"
android:listSelector="@drawable/listitem_selector"
tools:listitem="@layout/item_customer_in_queue">
</ListView>
项目布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_in_queue_list"
android:layout_width="match_parent"
android:layout_height="@dimen/in_queue_item_height"
android:minHeight="@dimen/in_queue_item_height"
android:background="@color/bckg"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.95">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<ImageView.../>
<ImageView.../>
<ImageView.../>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<ImageView.../>
<ImageView.../>
</RelativeLayout>
<TextView.../>
<TextView.../>
<TextView.../>
<LinearLayout <=here my LinearLayout of my issue
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_weight="0.1"
android:layout_gravity="bottom"/>
<TextView
android:id="@+id/list_dueTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" <=here my issue
android:text="due"
android:layout_weight="0.8"
android:textColor="@color/dark_grey"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<ProgressBar.../>
</LinearLayout>
【问题讨论】:
-
你能显示你的问题吗??
-
layout_gravity="bottom"of child 不能与具有orientation="vertical"的父 LinearLayout 一起使用 -
你试过 layout_gravity = "center" 吗?
-
@Ankit Kumar 我的问题就像你可以在屏幕截图上看到的那样,有时文本在左侧某个时候居中对齐,我只想居中对齐
-
@Alex 你能发一张你想要的截图吗
layout
标签: android android-layout android-listview textview gravity