我在我的android程序中使用图像作为线性布局的背景.我需要为此设置不透明度.任何人都可以告诉我我该怎么做?..半透明的图像不会显示不透明度,不会知道原因.提前感谢您的宝贵意见
如果以编程方式设置LinearLayout的背景,这不应该是任何问题.
您正在寻找的是Drawable.setAlpha(int alpha)方法.从个人项目:
ImageView image = (ImageView) row.findViewById(R.id.list_icon);
image.setImageResource(R.id.something);
image.setAlpha(110);
Run Code Online (Sandbox Code Playgroud)
不是很相似,但也许你明白了.
您使用drawable作为布局的背景.这里的挑战是让变量代表你的drawable.这是在这里完成的:
在布局的活动中:
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);
Run Code Online (Sandbox Code Playgroud)
它应该工作.至少它对我有用.
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           5023 次  |  
        
|   最近记录:  |