2017-04-05 61 views
-1

我創建了一個有趣的應用程序。 我創建了一個總是像浮動操作按鈕一樣的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上不是?

+0

儘量把你的ImageView用的FrameLayout –

+0

請參閱此鏈接http://stackoverflow.com/questions/27693843/androidelevation-doesnt- work-on-devices-pre-lollipop-with-compile-api21 –

+0

Elevation屬性從API 21開始,較早的API版本無法執行該佈局命令。 –

回答

0

嘗試調用此:

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> 
+0

如果我編寫imageView.bringToFront(),它不起作用;在我的onCreate()它仍然看起來像這樣https://gyazo.com/9275e291f215d92d5e7f2b8740a3d749 –

+0

@ TheUseraccawd檢查編輯答案.. – rafsanahmad007