我正在使用这种布局使图像和文本在中心.但它不工作.我只是使用android:layout_centerHorizontal ="true".为什么它不工作我不明白.有人可以帮忙解决这个问题吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:background="@drawable/image_tutorial1" />
<TextView
android:textSize="14dp"
android:id="@+id/title"
android:layout_below="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/info4"
android:textColor="#000000"
android:textStyle="bold" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在布局中,RelativeLayout宽度设置为wrap-content,它根本不占用整个可用宽度.它的内容都被集中,但他们的父母View正在缩小,以适应他们周围.
尝试fill_parentroot:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
Run Code Online (Sandbox Code Playgroud)
另外,LinearLayout与orientation="vertical"和gravity="center_horizontal"会做同样的,也更容易.
| 归档时间: |
|
| 查看次数: |
6727 次 |
| 最近记录: |