IT박스

(이미지)보기 알파에 대한 Android 및 설정 알파

itboxs 2020. 7. 24. 07:53
반응형

(이미지)보기 알파에 대한 Android 및 설정 알파


XML 속성에 대응하는 것이 실제로 setAlpha(int)없습니까?

그렇지 않다면 어떤 대안이 있습니까?


아니요, ImageView.setAlpha (int) 문서 에서 "관련 XML 속성"섹션이 누락 된 방법을 참조하십시오 . 대안은 사용하는 것입니다 View.setAlpha (플로트) 누구의 XML 대응 입니다 . 0에서 255가 아닌 0.0에서 1.0 사이의 범위가 필요합니다.android:alpha

<ImageView android:alpha="0.4">

그러나 후자는 API 레벨 11 이후에만 사용 가능합니다.


다른 답변보다 쉽습니다. alpha이중 값을 취하는 xml 값 이 있습니다.

android:alpha="0.0" 그 보이지 않는

android:alpha="0.5" 시스루

android:alpha="1.0" 완전히 보이는

그것이 작동하는 방식입니다.


XML에 대해서는 잘 모르지만 다음과 같은 방법으로 코드로 XML을 수행 할 수 있습니다.

ImageView myImageView = new ImageView(this);
myImageView.setAlpha(xxx);

API 이전 11 :

  • 범위는 0 ~ 255 (포함)이며 0은 투명하고 255는 불투명합니다.

API 11+에서 :

  • 범위는 0f에서 1f (포함)이며 0f는 투명하고 1f는 불투명합니다.

단색 배경에 유용한 대안 일 수 있습니다 .

있는 LinearLayout을 오버 이미지 뷰 와 사용할 수 있는 LinearLayout을 불투명 필터로. 다음은 검정색 배경의 작은 예입니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000" >

<RelativeLayout
    android:id="@+id/relativeLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

    <LinearLayout
        android:id="@+id/opacityFilter"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#CC000000"
        android:orientation="vertical" >
    </LinearLayout>
</RelativeLayout>

LinearLayoutandroid : background 속성을 # 00000000 (완전 투명)과 # FF000000 (완전 불투명) 사이에서 바꿉니다 .


이제 XML 대안이 있습니다.

        <ImageView
        android:id="@+id/example"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/example"
        android:alpha="0.7" />

그것은이다 : 안드로이드 : 알파 = "0.7"

0 (투명)에서 1 (불투명) 사이의 값.


use android:alpha=0.5 to achieve the opacity of 50% and to turn Android Material icons from Black to Grey.


Use this form to ancient version of android.

ImageView myImageView;
myImageView = (ImageView) findViewById(R.id.img);

AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F);
alpha.setDuration(0); 
alpha.setFillAfter(true); 
myImageView.startAnimation(alpha);

setAlpha(int) is deprecated as of API 16: Android 4.1

Please use setImageAlpha(int) instead


The alpha can be set along with the color using the following hex format #ARGB or #AARRGGBB. See http://developer.android.com/guide/topics/resources/color-list-resource.html

참고URL : https://stackoverflow.com/questions/4931071/android-and-setting-alpha-for-image-view-alpha

반응형