Posso impostare in modo programmatico l'alfa di un ImageView senza la necessità di dipendere dal livello API 11 in cui è stato introdotto setAlpha?Imposta alfa su ImageView senza setAlpha
risposta
Penso (ma non so per certo) che è possibile applicare un'animazione alfa a ImageView, e fintanto che fillAfter() è impostato su true nell'animazione, l'immagine deve rimanere a qualsiasi livello alfa finisce a
ImageView ha un metodo setAlpha(int) dal livello 1 dell'API. Quindi è possibile utilizzarlo in qualsiasi livello API.
È il metodo setAlpha(float) di View che viene introdotto nel livello API 11.
@joynes Dovrebbe essere accettato risposta – ruX
Usa 'setImageAlpha (X)' per la versione SDK> = 16! – tipycalFlow
Penso che l'ultimo commento sia molto più utile. – Vyacheslav
è possibile effettuare una nuova disposizione con solo immagine ur, impostare l'alfa necessario per il layout, impostarla come sovrapposizione e gonfiare quando volere.
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>
Ho usato il codice per impostareAlpha dell'immagine stessa, non la vista. Questo è disponibile dal livello di 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;
}
}
Ohh .. c'è un setAlpha (int alfa) e in questo è ImageView lavorativi dal livello di API 1 :) – joynes