2012-03-13 5 views

答えて

2

ImageViewにアルファアニメーションを適用できるとは思いますが(もちろんわかりませんが)、アニメーションでfillAfter()がtrueに設定されている限り、Imageはどのアルファレベルでも保持する必要があります〜で終わります。

+0

から作業thatsの私はただ単純に答えを見つけた:) .. 。 上記を参照。 – joynes

+0

これは確かに行く方法です – FoamyGuy

40

ImageViewには、APIレベル1からメソッドsetAlpha(int)があります。したがって、任意のAPIレベルで使用できます。
これは、APIレベルで導入されるViewsetAlpha(float)方法がある11

+3

@joynes回答を受け入れる必要があります – ruX

+1

SDKのバージョンが> = 16の場合は 'setImageAlpha(X)'を使用してください! – tipycalFlow

+0

私は最後のコメントがずっと便利だと思います。 – Vyacheslav

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

画像を表示するのではなく、画像のアルファを設定するコードを使用しました。これは...

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; 
    } 
} 
関連する問題