线性布局背景图像集alpha

时间:2012-06-23 15:58:08

标签: android

我在我的android程序中使用图像作为线性布局的背景。我需要为此设置不透明度。任何人都可以告诉我我该怎么做?..半透明的图像不会显示不透明度,虽然不知道原因。 提前感谢您的宝贵意见

1 个答案:

答案 0 :(得分:6)

如果以编程方式设置LinearLayout的背景,这不应该是任何问题。

您正在寻找的是Drawable.setAlpha(int alpha)方法。来自个人项目:

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

不一样,但也许你明白了。

您使用drawable作为布局的背景。这里的挑战是让变量代表你的drawable。完成此操作here

在布局活动中:

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);

它应该有效。至少它对我有用。

相关问题