2012-03-13 111 views

回答

2

我認爲(但不知道肯定)你可以對你的ImageView應用一個alpha動畫,並且只要fillAfter()在動畫上設置爲true,Image應該停留在任何alpha級別結束於。

+0

我只是發現了簡單的答案:) .. 。 往上看。 – joynes 2012-03-13 21:17:33

+0

那肯定是要走的路呢 – FoamyGuy 2012-03-13 21:27:31

40

ImageView有一個方法setAlpha(int)因爲API水平1.所以你可以在任何API級別使用它。
這是ViewsetAlpha(float)方法,在API層面推出11

+3

@joynes應該被接受回答 – ruX 2014-01-08 09:36:47

+1

使用'setImageAlpha(X)'SDK版本> = 16! – tipycalFlow 2014-09-28 05:55:07

+0

我認爲最後的評論更有用。 – Vyacheslav 2015-06-13 18:52:28

2

你可以只用烏爾圖像的新佈局,設置所需佈局的α,將其設置爲覆蓋和膨脹你的時候想。

LayoutInflater inflater = LayoutInflater.from(this); 
     View overView = inflater.inflate(R.layout.myAlpahImageLayout, null); 
     this.addContentView(overView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 


<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:alpha="0.5" 
    tools:context=".MainActivity" > 

    <ImageView 
     android:id="@+id/myImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/myImage1" /> 

</RelativeLayout> 
4

我用代碼來設置圖像本身,而不是視圖的Alpha。這可從API級別1 ..

public void toggleButton(int i) { 
    if (indImageBtnEnabled[i]) { 

     int di = getDrawableId(findViewById(myImagebtns[i])); 
     Drawable d = this.getResources().getDrawable(di); 
     d.setAlpha(25); 

     ((ImageView) findViewById(myImagebtns[i])).setImageDrawable(d); 

     indImageBtnEnabled[i] = false; 
    } else { 
     // findViewById(myImagebtns[i]).setAlpha(1f) << NEEDS API11; 
     int di = getDrawableId(findViewById(myImagebtns[i])); 
     Drawable d = this.getResources().getDrawable(di); 
     d.setAlpha(255); 

     ((ImageView) findViewById(myImagebtns[i])).setImageDrawable(d); 

     indImageBtnEnabled[i] = true; 
    } 
} 
相關問題