我有以下布局:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<ImageView
android:id="@+id/personal_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/dom_logo_new" />
<ImageView
android:id="@+id/round_corner_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/corner_white_left_top" />
<ImageView
android:id="@+id/round_corner_top_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/corner_white_right_top" />
<ImageView
android:id="@+id/round_corner_bottom_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/corner_white_left_bottom" />
<ImageView
android:id="@+id/round_corner_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/corner_white_right_bottom" />
</RelativeLayout>
有 1 张主图(personal_image)和 4 张小图。
我需要在屏幕的水平中心显示主图像 (personal_image),每个角有 4 个图像(左上、右上、左下、右下)。但是 RelativeLayout
具有所有屏幕的宽度和高度。
如何设置 RelativeLayout
的 width
和 height
相同的 width
和 height
的 personal_image??
最佳答案
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<ImageView
android:id="@+id/personal_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/round_corner_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/round_corner_top_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/round_corner_bottom_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/round_corner_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/round_corner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
</LinearLayout>
当您使用环绕内容时,您不必担心不同的屏幕尺寸。它会自行管理。
关于机器人 : Relative layout width wrap_content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11578990/