我正在尝试将文本视图放在ListView项的中间。
因此,我创建了一个LinearLayout,它处理圆圈和其中的文本视图。
圆圈是一个形状:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="@color/accentColor"></solid>
</shape>我希望TextView是垂直的居中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/vplan_list_item_hour"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/rectangle"
android:gravity="center"
android:text="1"
android:textSize="25sp" />
</LinearLayout>
...
</RelativeLayout>它看起来就在android的“设计”选项卡上:

但是当我运行这个应用程序时,它看起来是这样的:

有没有人知道怎么解决这个问题?
发布于 2015-12-13 15:37:45
使用形状作为背景
可绘图中的shape_rounded.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="24dp"/>
<solid android:color="#A5A5A5" />
</shape>布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp" >
<TextView
android:id="@+id/vplan_list_item_hour"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/shape_rounded"
android:gravity="center"
android:text="1"
android:layout_margin="16dp"
android:textSize="25sp" />
</RelativeLayout>发布于 2015-12-13 15:55:01
你试过用RelativeLayout来做吗?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp">
<TextView
android:id="@+id/vplan_list_item_hour"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:background="@drawable/rectangle"
android:gravity="center"
android:text="1"
android:textSize="25sp" />
...
</RelativeLayout>
</RelativeLayout>发布于 2015-12-14 10:41:33
我试着简化你的布局。我在Genymotion (包括Android4.4)中测试了它--它的功能很有魅力。试试看。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp">
<TextView
android:id="@+id/vplan_list_item_hour"
android:layout_centerVertical="true"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:background="@drawable/shape_rounded"
android:gravity="center"
android:textSize="25sp"
android:text="1" />
</RelativeLayout>希望,这有帮助
https://stackoverflow.com/questions/34252561
复制相似问题