机器人 : Relative layout width wrap_content

标签 android imageview width android-relativelayout

我有以下布局:

<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 具有所有屏幕的宽度和高度。

如何设置 RelativeLayoutwidthheight 相同的 widthheight 的 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/

相关文章:

android - View 中的屏幕高度和宽度

java - 预期 Android API 级别为 21+,但在使用 Retrofit 2、OkHttp3 时为 19

android - 在我的每个列表项上显示缩略图

android - 在 res 文件夹中的微调器中显示图像

安卓 : Low memory error when trying to create slide show using ViewFlipper

javascript - JqPlot 图形太宽

jquery写css宽度

android - 如何从浏览器 Intent 中获取授权 token ?

android - 选择 .xls/.xlsx 并读取其数据

android - EditText afterTextChanged 不工作 : displays null