如何让安卓(Android)子控件超出父控件的范围显示
先来看一张预览图:
废话不多说,直接上代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="60dp"
android:background="@mipmap/www" />
<LinearLayout
android:id="@+id/ll_bottom"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#F8549D"
android:elevation="10dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher" />
</RelativeLayout>
<RelativeLayout
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:background="@drawable/bottom_bg_shape">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerInParent="true"
android:src="@mipmap/icon_go" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@mipmap/ic_launcher" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
这张图呢是我刚刚做的,效果是参考了酷狗音乐播放器来完成的,我想说明重点在底部的导航栏:如图

再来一张反效果预览图:
如何使得蓝色圆形的播放键的显示越过粉色的范围。当然经过合理的布局是可以达到这样的效果的,但是却有更简单的方法。也就是在根布局的属性中加入一个来自Android自身提供的属性:
android:clipChildren="false"
属性解释和说明:
1、android:clipChildren的意思:是否限制子View在其范围内
2、可以通过android:layout_gravity控制超出的部分如何显示。
3、只需在根节点设置android:clipChildren为false即可,默认为true
总结
以上就是如何让安卓(Android)子控件超出父控件的范围显示出来的全部内容,大家学会了吗?希望本文可以帮助到各位。
相关文章
Android Studio开发中Gradle各种常见报错问题解决方案
这篇文章主要为大家介绍了Android Studio开发中Gradle各种常见报错问题解决方案,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-12-12
Android编程实现为ListView创建上下文菜单(ContextMenu)的方法
这篇文章主要介绍了Android编程实现为ListView创建上下文菜单(ContextMenu)的方法,简单分析了上下文菜单的功能及ListView创建上下文菜单(ContextMenu)的具体步骤与相关操作技巧,需要的朋友可以参考下2017-02-02
Android搜索框(SearchView)的功能和用法详解
这篇文章主要为大家详细介绍了Android搜索框SearchView的功能和用法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-05-05


最新评论