Android 子view超出父view范围绘制

相信在看到我的这篇博客之前,各位道友已经看过其他相关的博客了,so let’s take all bullshit out.
我在初次尝试超过父view绘制子view的操作时,总是失败。我甚至在布局文件的各个父view中添加了android:clipChildren=”false”,还是失败了。代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    tools:context="com.example.bigyoung.overpicture.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#000"
        android:layout_centerInParent="true">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_gravity="bottom"
            >
            <ImageView
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_gravity="bottom"
                android:contentDescription="hahha"
                android:src="@mipmap/desert"
                />
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

接下来是其他博客上成功的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipChildren="false">

    <LinearLayout
        android:id="@+id/ll_bottom"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">
        <RelativeLayout
            android:layout_width="100dp"
            android:layout_height="90dp"
            android:layout_gravity="bottom">

            <ImageView
                android:id="@+id/dd5"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_centerInParent="true"
                android:src="@mipmap/desert" />
            <TextView
                android:padding="2dp"
                android:textSize="10sp"
                android:layout_centerInParent="true"
                android:text="添加"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/dd5"/>

        </RelativeLayout>
   </LinearLayout>
  </RelativeLayout>

发现了不同了没有?发现了发现了,imgview引用的图片不同。开个玩笑,当然不是这个原因。原因是被子类超出的父view是LinearLayout,而失败的是RelativeLayout.想起来之前读过的一篇博客,里面探讨了LinearLayout控件对子view的layout_gravity属性的限制。那么RelativeLayout是不是也限制了子view不能超出父view绘制呢。很可惜,目前我没有找到相关文章。
值得一提的是,就像安卓的视图动画一样,超出父view绘制而成的img部分,不能响应点击事件。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值