2

Android プログラムで線形レイアウトの背景として画像を使用しています。これには不透明度を設定する必要があります。これを行う方法を誰か教えてもらえますか?..半透明の画像には不透明度が表示されません。理由はわかるが。貴重なご意見をお寄せいただきありがとうございます

4

1 に答える 1

6

プログラムで LinearLayout の背景を設定する場合、これは問題になりません。

あなたが探しているのはDrawable.setAlpha(int alpha)方法です。個人的なプロジェクトから:

ImageView image = (ImageView) row.findViewById(R.id.list_icon);
image.setImageResource(R.id.something);
image.setAlpha(110);

まったく同じではありませんが、要点はわかるでしょう。

レイアウトの背景としてドローアブルを使用しています。ここでの課題は、ドローアブルを表す変数を取得することです。これはここで行われます:

レイアウトへのアクティビティ:

Resources res = getResources();
Drawable background = res.getDrawable(R.drawable.*the id*);
    // The layout which are to have the background:
LinearLayout layout = ((LinearLayout) findViewById(R.id.*you get it*));
    // Now that we have the layout and the background, we ajust the opacity 
    // of the background, and sets it as the background for the layout
background.setAlpha( *a number* );
layout.setBackgroundDrawable(background);

そして、それはうまくいくはずです。少なくとも私にとってはうまくいきました。

于 2012-06-23T16:28:50.807 に答える