I have defined a layer-list with a couple of items on an xml file. The items are displayed o.k. I want every five second or so one of the layers to become invisible.
It works o.k. for a simple textview for example but not for the Layer inside the LayerDrawable
final private Runnable runnable = new Runnable() {
public void run() {
LayerDrawable myDrawable= (LayerDrawable)getResources().getDrawable(R.drawable.all_layers);
Drawable layer = myDrawable.findDrawableByLayerId(R.id.interesting_layer);
if (layer.isVisible()==true)
{
layer.setVisible(false, false);
}
else
{
layer.setVisible(true, false);
}
TextView txt = (TextView) findViewById(R.id.txtTest);
if (txt.getVisibility()==0)
{
txt.setVisibility(4);
}
else
{
txt.setVisibility(0);
}
handler.postDelayed(this, 5000);
}
};
Do I try to get the Id of the layer in a wrong way (I found it from here...)? Thanks in advance!
I did that playing with the alpha of the layer. This code will make your layer disappear:
layer.setAlpha(0);
And then you can display it again with:
layer.setAlpha(255);
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With