Note that there are some explanatory texts on larger screens.

plurals
  1. POImagebutton from drawable in layer-list?
    text
    copied!<p>I've looked for hours for the answer to this seemingly simple issue I'm having.</p> <p>Basically, how do you make a certain drawable in a layer-list an imagebutton? </p> <p>Eclipse doesn't mark this code with any errors yet when it runs I get a force close. What am I missing? </p> <p>Also --</p> <p>Do I use <code>findViewById</code> to reference resources even when they're in a layer-list?</p> <p>Does the <code>android:id</code> in the XML file belong with the <code>item</code> tag or the <code>bitmap</code> tag?</p> <p>EDIT: This code is just something I put together quickly to demonstrate my issue. I'm trying to make just the last layered drawable the active button. For example for a UI I am laying a bunch or graphics on top of one another, the last two layers will be buttons that I want to make active. Is that possible? Or maybe there's a better way to do what I'm trying to do?</p> <p>Thanks.</p> <hr> <p>layers.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item&gt; &lt;bitmap android:src="@drawable/android_red" android:gravity="center" /&gt; &lt;/item&gt; &lt;item android:top="10dp" android:left="10dp"&gt; &lt;bitmap android:src="@drawable/android_green" android:gravity="center" /&gt; &lt;/item&gt; &lt;item android:id="@+id/blue_button" android:top="20dp" android:left="20dp"&gt; &lt;bitmap android:src="@drawable/android_blue" android:gravity="center" /&gt; &lt;/item&gt; &lt;/layer-list&gt; </code></pre> <hr> <p>main.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/layers" /&gt; &lt;/LinearLayout&gt; </code></pre> <hr> <p>Activity:</p> <pre><code>public class LayoutTestActivity extends Activity implements OnClickListener { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FILL_PARENT,WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); ImageButton imgStartButton = (ImageButton) findViewById(R.id.blue_button); imgStartButton.setOnClickListener(this); } public void onClick(View v) { } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload