【问题标题】:Why ImageView is not crossing the relativelayout为什么 ImageView 没有越过 relativelayout
【发布时间】:2017-11-15 08:54:08
【问题描述】:

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

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

<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>

【问题讨论】:

    标签: android android-imageview android-relativelayout


    【解决方案1】:

    RelativeLayout 是父级,ImageView 是其中的子级。规则是,如果子项大于父项,则子项将被剪裁,以便只有适合父项的内容可见。所以如果parent的身高是50dp,child的身高是100dp,你只会看到child的50dp的内容。

    如果您想查看(在这种情况下)完整的 ImageView 内容,请将 RelativeLayout 的 layout_height 更改为 wrap_content。如果要完成图片中的布局,请不要将 ImageView 作为 RelativeLayout 的子级。

    【讨论】:

      【解决方案2】:

      使用两个相对布局

      <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>
      

      【讨论】:

        猜你喜欢
        • 2014-11-10
        • 2011-08-03
        • 1970-01-01
        • 1970-01-01
        • 2021-03-17
        • 1970-01-01
        • 2017-05-12
        • 2014-11-19
        • 1970-01-01
        相关资源
        最近更新 更多