Android 线性布局背景图像集alpha

Android 线性布局背景图像集alpha,android,Android,我在android程序中使用图像作为线性布局的背景。我需要为此设置不透明度。有人能告诉我怎么做吗?。半透明的图像不显示不透明度,但不知道原因。 提前感谢您的宝贵意见如果您以编程方式设置线性布局的背景,这应该不会有任何问题 您需要的是Drawable.setAlpha(int-alpha)方法。来自个人项目: ImageView image = (ImageView) row.findViewById(R.id.list_icon); image.setImageResource(R.id.som

我在android程序中使用图像作为线性布局的背景。我需要为此设置不透明度。有人能告诉我怎么做吗?。半透明的图像不显示不透明度,但不知道原因。
提前感谢您的宝贵意见

如果您以编程方式设置线性布局的背景,这应该不会有任何问题

您需要的是
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);

它应该会起作用。至少它对我有用

可以将XML代码粘贴到定义背景的位置吗?你是指一个可画的还是直接指图片?请把代码放在你的问题中,而不是作为评论。对不起,我不能这样做。。。重要的一行是android:background=“@drawable/ic_launcher”我明白了。。。好吧,我会尝试添加一个答案,也许会有帮助。非常感谢您的宝贵努力。