Note that there are some explanatory texts on larger screens.

plurals
  1. POComposite control from LinearLayout get messed up when replaced with merge
    primarykey
    data
    text
    <p>I want to create a composite view from a bunch of controls, by extending a LinearLayout. I'm using an XML file to specify the inner layout of my custom control. I'm inflating the custom control from the code via <code>LayoutInflater</code>.</p> <h2>The Problem is:</h2> <p>If i replace the root <code>LinearLayout</code> element to a <code>merge</code> element in the XML, my whole layout fall apart. If I don't, then I only encapsulated a <code>LinearLayout</code> with my custom one.</p> <h2>The question is:</h2> <p>What do i have to change in the merge layout, so my view looks like how a linear layout should?</p> <h1>How it looks like:</h1> <p>With <code>LinearLayout</code> (this is how i want it to look like):<br> <a href="http://oi45.tinypic.com/2pqwby1.jpg" rel="nofollow">http://oi45.tinypic.com/2pqwby1.jpg</a></p> <p>With <code>merge</code> (this is the tag i want to use):<br> <a href="http://i45.tinypic.com/155j4o0.png" rel="nofollow">http://i45.tinypic.com/155j4o0.png</a></p> <h1>The code:</h1> <h2>TowerLayout.java (no problems here, just in case):</h2> <pre><code>public class TowerLayout extends LinearLayout implements OnClickListener { public TowerLayout(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater.from(context).inflate(R.layout.tower_layout, this, true); //this is what i want to use. //((LinearLayout)findViewById(R.id.root)).setOnClickListener(this); //this is the current ugly workaround. this.setClickable(true); setOnClickListener(this); } @Override public void onClick(View v) { Toast.makeText(getContext(), "Foo", Toast.LENGTH_SHORT).show(); } } </code></pre> <h2>What i have in Tower_Layout.xml:</h2> <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="match_parent" android:layout_height="match_parent" android:clickable="true" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:duplicateParentState="true"&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="TowerA" android:textAppearance="?android:attr/textAppearanceLarge" android:duplicateParentState="true" android:textSize="32sp" /&gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="0.28" android:duplicateParentState="true" android:src="@drawable/icon" /&gt; &lt;/LinearLayout&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Basic information" android:duplicateParentState="true" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_marginLeft="15dip" android:layout_height="wrap_content" android:duplicateParentState="true" android:text="Lorem ipsum dolor sit amet, consectetuer adipiscing elit." /&gt; &lt;TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:duplicateParentState="true" android:text="16m" android:textAppearance="?android:attr/textAppearanceLarge" android:textSize="100sp" /&gt; </code></pre> <p></p> <h2>What i want in Tower_Layout.xml:</h2> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:duplicateParentState="true"&gt; ... &lt;/LinearLayout&gt; ... &lt;/merge&gt; </code></pre> <h2>One more thing:</h2> <p>I know, the screenshots are from the eclipse designer, but believe me: they look like this on android phone as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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