ImageView应该总是高于
我创建了一个有趣的应用程序。 我创建了一个总是像浮动操作按钮一样的ImageView。 问题IST:一切工作正常,在Android 5.0以上版本,它看起来像这样: https://gyazo.com/0f02bbe0130defd03cc5ce6282d8e321ImageView应该总是高于
而且与Android 4在每个设备上,它看起来像这样: https://gyazo.com/9275e291f215d92d5e7f2b8740a3d749
这是代码为ImageView的:
<ImageView
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/infoicon"
android:adjustViewBounds="true"
android:maxWidth="25dp"
android:maxHeight="25dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:elevation="10dp"/>
这条线应该提升的ImageView:
android:elevation="10dp"
为什么它在Android版本5或更高版本上工作,但是在Android版本4上不是?
尝试调用此:
imageView.bringToFront();
在onCreate()
和onResume()
编辑
试试你的包裹里面的ImageView Framelayout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:adjustViewBounds="true"
android:elevation="10dp"
android:maxHeight="25dp"
android:maxWidth="25dp"
android:src="@drawable/infoicon" />
</FrameLayout>
如果我编写imageView.bringToFront(),它不起作用;在我的onCreate()它仍然看起来像这样https://gyazo.com/9275e291f215d92d5e7f2b8740a3d749 –
@ TheUseraccawd检查编辑答案.. – rafsanahmad007
android:elevation
已添加到API级别21,因此它仅适用于API级别为21或更高的Android设备。
如果您需要为低于API级别21设备提供标高,请参阅How to implement the Material-design Elevation for Pre-lollipop
链接不解释这种情况 –
尽量把你的ImageView用的FrameLayout –
请参阅此链接http://*.com/questions/27693843/androidelevation-doesnt- work-on-devices-pre-lollipop-with-compile-api21 –
Elevation属性从API 21开始,较早的API版本无法执行该布局命令。 –