我已经通过代码定义了一些包含少量项目的LayerDrawable,但我不知道如何在“imagen”具有的LayerDrawable中设置每个层的可见性。这是我的代码:
public class layerExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imagen = (ImageView)findViewById(R.id.image);
Resources r = getResources();
Drawable[] capas = new Drawable[3];
capas[0] = r.getDrawable(R.drawable.icon);
capas[1] = r.getDrawable(R.drawable.icon2);
capas[2] = r.getDrawable(R.drawable.icon3);
LayerDrawable capasDrawable = new LayerDrawable(capas);
imagen.setImageDrawable(capasDrawable);
答案 0 :(得分:2)
您可以拨打
<drawable object>.setAlpha(int i)
i:0表示完全透明,255表示完全不透明