Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Its a bit difficult to tell exactly what you want, but it sounds like you are asking for two different things, which (generally) isn't possible with only one layout. Basically from what I interpret, you are saying I want the button to be the same size as the image, and then saying I <em>don’t</em> want the button to be the same size as the image (when its too big).</p> <p>My suggestion is to incorporate a way to decipher which layout style you want. Perhaps it is by checking the image size vs the current screen size. Then apply the type of parameters that will work for that particular layout.</p> <p>Setting the two the same size is easy via use of the XML <code>android:layout_weight</code> parameter, and you are already familiar with <code>wrap_content</code> for use with a larger image. While you can use these two parameters together you won't get what you want in all cases (again assuming I understand your post). You'll need one layout using weights to make the views the same size and another using wrap_content to allow for different sizes.</p> <p>Also, just a side note, I would really recommend using XML for layouts unless there is something specific you can't accomplish with XML.</p> <p><strong>Edit:</strong> Here is an example for you.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/button_1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="short" /&gt; &lt;Button android:id="@+id/button_2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="medium" /&gt; &lt;Button android:id="@+id/button_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="loooooooooong" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><img src="https://i.stack.imgur.com/cktS3.png" alt="enter image description here"></p>
 

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