android中elevation属性对布局的影响!

作者:燕歆波
导读:elevation属性对布局层次的影响!

现象

在这里插入图片描述
在相对布局中,添加了一个输入框和一张搜索的图标,看效果图:

在这里插入图片描述可以发现,搜索图标并没有显示出来,好在今天脑子比较好使,我直接想法就是去改elvation属性,果然,发现了有意思的东西;
在这里插入图片描述
给ImageView添加elvation属性之后,发现并没有使图表显示出来,又想到可能是elevation的值太小???
于是我把ImageView的elevation的值改成8dp
在这里插入图片描述然后再看效果:
在这里插入图片描述
搜索图标出来了,再次修改ImageView的elevation为6dp,和输入框一样,发现也是可以显示的;

总结

elevation有提高元素层级的能力,就像html的z-index一样,值相同代表相同层级,值不同,大的层级高,
搜索相关博客后,发现果然如此!

要在Android使用约束布局来创建工具栏,可以按照以下步骤操作: 1. 在XML布局文件创建一个约束布局容器作为根布局。 2. 在约束布局容器添加一个Toolbar工具栏控件,并设置其id和高度。 3. 在Toolbar控件下方添加一个View控件,并设置其高度为0dp。 4. 使用约束布局的约束属性将Toolbar控件和View控件进行约束,使得Toolbar控件在顶部居显示,并且View控件在Toolbar控件下方并且占据剩余空间。 以下是一个示例代码: ``` <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:elevation="4dp" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/> <View android:id="@+id/view" android:layout_width="0dp" android:layout_height="0dp" android:background="?android:attr/windowBackground" app:layout_constraintTop_toBottomOf="@id/toolbar" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent"/> </androidx.constraintlayout.widget.ConstraintLayout> ``` 在这个布局,Toolbar控件被设置为根布局的顶部,并且View控件被约束在Toolbar控件下方并且占据剩余空间。你可以根据自己的需求对Toolbar和View进行调整。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值