如何带来的ImageView在巴顿前面在android系统5? [英] How to bring ImageView in front of Button in android 5?
问题描述
在Android的版本previous到棒棒糖,下面code ++工程和图像是在按钮的前面。但在Android的5 ImageView的放在后面的按钮。
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直><按钮
机器人:ID =@ + ID /按钮
机器人:layout_width =210SP
机器人:layout_height =210SP
机器人:layout_centerHorizontal =真
机器人:layout_centerVertical =真
机器人:背景=@绘制/ round_button
机器人:drawablePadding =10dip
机器人:重力=center_vertical | CENTER_HORIZONTAL/>
< ImageView的
机器人:ID =@ + ID / ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentTop =真
机器人:layout_centerHorizontal =真
机器人:contentDescription =@字符串/火炬
机器人:SRC =?ATTR / ImageView的/> < / RelativeLayout的>
这个问题似乎是Android 5.0的海拔
属性。显然, RelativeLayout的
Z轴排序扎成海拔
。如果这两个部件具有相同的海拔
的 RelativeLayout的
将确定的Z轴顺序 - 你可以看到,如果你要切换布局既按钮
部件,例如。然而,如果一个小部件(按钮
)有一个海拔
,和另一个小部件( ImageView的
)不,海拔
将采取precedence。
您可以删除按钮
海拔
通过的android:stateListAnimator =@空
或定义自己的自定义动画。或者,你可以添加一些海拔
你的的ImageView
来得到它是在Z轴上高于是按钮
。
In android versions previous to lolipop, the following code works and an image is in front of the button. But in android 5 the imageview is put behind the button.
<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:orientation="vertical" >
<Button
android:id="@+id/button"
android:layout_width="210sp"
android:layout_height="210sp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/round_button"
android:drawablePadding="10dip"
android:gravity="center_vertical|center_horizontal" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/torch"
android:src="?attr/imageview" />
</RelativeLayout>
The problem appears Android 5.0's elevation
property. Apparently, the RelativeLayout
Z-axis ordering is tied into elevation
. If both widgets have the same elevation
, the RelativeLayout
will determine the Z-axis order -- you can see that if you were to switch your layout to be both Button
widgets, for example. However, if one widget (Button
) has an elevation
, and another widget (ImageView
) does not, the elevation
will take precedence.
You can remove the Button
elevation
via android:stateListAnimator="@null"
or by defining your own custom animator. Or, you can add some elevation
to your ImageView
to get it to be higher on the Z axis than is the Button
.
这篇关于如何带来的ImageView在巴顿前面在android系统5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!