为什么ImageView没有穿过relativelayout

时间:2017-11-15 08:54:08

标签: android android-imageview android-relativelayout

我在RelativeLayout中有一个ImageView。 RelativeLayout高度固定为50dp,ImageView高度大于50dp。我希望我的ImageView穿过RelativeLayout。

我附上了一个我想要实现的屏幕。

enter image description here

<RelativeLayout
android:id="@+id/btnMenu"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#000000"
            android:clipChildren="false"
            android:clipToPadding="false">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@drawable/home_menu"
                android:layout_alignParentLeft="true"/>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@drawable/home_logo_bottom"
                android:layout_alignParentRight="true"/>

        </RelativeLayout>

2 个答案:

答案 0 :(得分:1)

RelativeLayout是父级,ImageView是其中的子级。规则是,如果子项大于父项,则子项将被剪裁,以便只有符合父项的内容才可见。因此,如果父母的身高是50dp,孩子的身高是100dp,那么你只能看到孩子的50dp内容。

如果您想查看(在本例中)完整的ImageView内容,请将RelativeLayout的layout_height更改为wrap_content。如果要像在图像中一样完成布局,请不要将ImageView作为RelativeLayout的子项。

答案 1 :(得分:0)

使用两个相对布局

<RelativeLayout
  android:id="@+id/parentlayout"
   android:layout_width="match_parent"
   android:layout_height="60dp"
   android:background="#000000">

  <RelativeLayout
  android:id="@+id/btnMenu"
   android:layout_width="match_parent"
   android:layout_height="50dp"
    android:layout_alignParentBottom="true"
     android:background="#000000">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:background="@drawable/home_menu"
            android:layout_alignParentLeft="true"/>


        </RelativeLayout>

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:background="@drawable/home_logo_bottom"
            android:layout_alignParentRight="true"/>

     </RelativeLayout>