Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid RelativeLayout - show items side by side when space but on separate lines when insufficient space?
    primarykey
    data
    text
    <p>I'm laying out an app which presents the results of a search in a ListView. I've defined each item to have a custom layout as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="?android:attr/listPreferredItemHeight" android:padding="5dp" android:paddingRight="?android:attr/scrollbarSize" &gt; &lt;TextView android:id="@+id/title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:ellipsize="end" android:textAppearance="?android:attr/textAppearanceSearchResultTitle" android:textIsSelectable="false" /&gt; &lt;TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@+id/title" android:layout_toRightOf="@+id/subtitle" android:gravity="bottom|right" android:textAppearance="?android:attr/textAppearanceSearchResultSubtitle" android:textIsSelectable="false" /&gt; &lt;TextView android:id="@+id/subtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/title" android:gravity="bottom|left" android:textAppearance="?android:attr/textAppearanceSearchResultSubtitle" android:textIsSelectable="false" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>This looks great when subtitle and date are of appropriate length to fit on a single line, however it looks awful if the subtitle consumes most of the line and forces date to take a very thin width and so wrap vertically.</p> <p>What I'd like to do is have them appear side-by-side when there's space but on separate lines if there isn't. I've tried fiddling with the various layout_* attributes and the gravity to no avail and the question isn't very Google-able (at least, I can't think of the right words to search for). Can anyone point me towards the combination of layout rules that I need to achieve this? Or perhaps a different container if one would be more appropriate?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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