您的位置:首页 > 移动开发 > Android开发

Android 子view超出父view范围绘制

2018-02-02 15:17 1146 查看
相信在看到我的这篇博客之前,各位道友已经看过其他相关的博客了,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部分,不能响应点击事件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: