包装内容时的位置变化

时间:2017-10-26 09:50:56

标签: android android-imageview

当我将widthheight更改为wrap_content ImageView时,他们的位置也会发生变化?我只想wrap_content heightwidthview的位置保持不变的任何解决方案

    <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/ammm">
            <ImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/t1"
                android:tag="p"
                android:layout_marginRight="5dp"
                android:background="@color/black"/>
            <ImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_marginRight="5dp"
                android:id="@+id/t2"
                android:tag="r"
                android:background="@color/white"
                android:layout_alignParentTop="true"
                android:layout_toEndOf="@+id/t1" />
            <ImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_marginRight="5dp"
                android:id="@+id/t3"
                android:tag="q"
                android:background="@color/brown"
                android:layout_alignParentTop="true"
                android:layout_toEndOf="@+id/t2" />
            <ImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="@color/blue"
                android:id="@+id/t4"
                android:tag="r"
                android:layout_alignParentTop="true"
                android:layout_toEndOf="@+id/t3" />

        </RelativeLayout>

1 个答案:

答案 0 :(得分:0)

尝试使用LinearLayout

<LinearLayout
    android:id="@+id/ammm"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/t1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:layout_weight="1"
        android:src="@mipmap/ic_launcher_round"
        android:tag="p" />

    <ImageView
        android:id="@+id/t2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginRight="5dp"
        android:src="@mipmap/ic_launcher_round"
        android:tag="r" />

    <ImageView
        android:id="@+id/t3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginRight="5dp"
        android:src="@mipmap/ic_launcher_round"
        android:tag="q" />

    <ImageView
        android:id="@+id/t4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/ic_launcher_round"
        android:tag="r" />

</LinearLayout>