Android和設置alpha(圖像)透明度


1. 沒有,沒有,怎么看“相關的XML屬性”一節中的ImageView.setAlpha(INT)缺少另一種方法是View.setAlpha(浮動)/android:alpha代替。然而,在僅因為API級別11后者。 
2. 它比其他的反應更容易。 有一個XML值alpha這需要雙重價值。Android:alpha="0.0"那看不見的Android:alpha="0.5"透視Android:alpha="1.0"全可見 這就是它的工作原理。 
3. 我不知道有關XML,但你可以通過代碼以下面的方式做到這一點。

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

其中0 <范圍<=255,0為透明,255表示不透明。 
4. 也許一個有用的替代純顏色的背景: 放的LinearLayout在ImageView的的的LinearLayout作為一個不透明的過濾器。在下面的一個小例子,有一個黑色的背景:

<LinearLayout xmlns:android=" CodeGo.net 
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>

改變android:在的LinearLayout之間#00000000(完全透明)和#FF000000(完全不透明)的背景屬性。 
5. 現在有一個XML的替代方案:

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

它是:android:alpha=“0.7” 用從0(透明)到1(不透明)的值。 
6. alpha可以設置連同下列十六進制格式ARGB#或#AARRGGBB。 看 
7. 使用此表來古老版本的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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM