RelativeLayout的一个特性

来源:互联网 发布:c语言的科学和艺术 pdf 编辑:程序博客网 时间:2024/06/05 03:30

实现效果为将ic_launcher压在上面图片(图片大小不固定)的最下面

**

>下面代码有误请直接查看评论,感谢“魏成林 ”的指正!!!

**

xml代码

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">        <ImageView            android:id="@+id/bannerImg"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:adjustViewBounds="true"            android:src="@drawable/img" />            <ImageView                android:id="@+id/activity_entrance"                android:layout_width="60dp"                android:layout_alignParentBottom="true"                android:layout_height="60dp"                android:layout_gravity="right"                android:src="@mipmap/ic_launcher" />    </RelativeLayout></LinearLayout>

但是上面xml文件实现的效果图如下

可以看到使用 android:layout_alignParentBottom=”true”属性的时候高度是按照match_parent计算的

解决办法在RelativeLayout外面嵌套一层ScrollView

xml代码

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">    <ScrollView        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:fillViewport="true">        <RelativeLayout            android:layout_width="match_parent"            android:layout_height="wrap_content">            <ImageView                android:id="@+id/bannerImg"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:adjustViewBounds="true"                android:src="@drawable/img" />            <ImageView                android:id="@+id/activity_entrance"                android:layout_width="60dp"                android:layout_height="60dp"                android:layout_alignParentBottom="true"                android:layout_gravity="right"                android:src="@mipmap/ic_launcher" />        </RelativeLayout>    </ScrollView></LinearLayout>

我只是记录了一下踩到坑的解决办法,但是为什么不知道原因,哪位大神如果知道原因,请在下面留言,感谢!!!

原创粉丝点击