setAlpha가 도입 된 API 레벨 11에 의존 할 필요없이 프로그래밍 방식으로 ImageView의 알파를 설정할 수 있습니까?setAlpha없이 ImageView에 알파를 설정
답변
ImageView은 API 레벨 1부터 메소드 setAlpha(int)입니다. 따라서 모든 API 레벨에서 사용할 수 있습니다.
은 API 수준에서 도입 View의 setAlpha(float) 방법은 11
@joynes 대답을 받아 들여야합니다 – ruX
SDK 버전이 16 이상이면'setImageAlpha (X)'를 사용하십시오! – tipycalFlow
나는 마지막 코멘트가 훨씬 더 유용하다고 생각한다. – Vyacheslav
당신은 오버레이로 설정하면 레이아웃에 필요한 알파를 설정, 단지 UR 이미지와 새로운 레이아웃을 만들 때 팽창 수 필요.
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>
코드를 사용하여보기가 아닌 이미지 자체의 알파를 설정합니다. 이
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;
}
}
오 .. 난 그냥 간단하게 대답을 :) 발견 1 : – joynes