0

I'm trying to create a view from a Custom List.

See picture below

layout

Colors : - blue is the Layout of the view - pink is a row from the list - red is a picture, size fixed located to the left - grey is a place to display 2 texts : a label and a value - orange is another picture, size fixed, which should be located to the right

I read a lot about layouts, but can't find a way to do this.

Whatever I try, if the text is too long it goes under the orange picture.

Here is the XML I'm using :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView
    android:id="@+id/flower_picture"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:background="@color/white"
    android:padding="1dp"
    android:scaleType="fitXY" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="start"
    android:orientation="horizontal">
    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LABEL" />
    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:ellipsize="end"
        android:maxLines="1" />
</LinearLayout>
<ImageView
    android:id="@+id/wateredbutton"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="@color/white"
    android:scaleType="fitXY" />
</LinearLayout>

I tried many things but can't find a way to limit the size of the text without setting a textSize of a layout_width.

I assumed that android would be able to detect that there are 3 layouts to display in a row, and would be able to limit the middle one to the desired size if needed.

Is there a way to do this ?

shadygoneinsane
  • 2,226
  • 1
  • 24
  • 47
Pierre
  • 83
  • 4

3 Answers3

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/flower_picture"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/white"
        android:padding="1dp"
        android:scaleType="fitXY" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_weight="3"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:lines="1"
            android:maxLines="1"
            android:text="LABEL" />

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:ellipsize="end"
            android:inputType="text"
            android:lines="1"
            android:maxLines="1" />
    </LinearLayout>

    <ImageView
        android:id="@+id/wateredbutton"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@color/white"
        android:scaleType="fitXY" />
</LinearLayout>

Use this will solve your problem,

Rishabh Mahatha
  • 1,251
  • 9
  • 19
0

if you want to limit your text view in a row. use relative layout and add toRightOff and give the picture id of right picture and it will limit it to left of picture and wont cut behind the picture

Usman Ghauri
  • 931
  • 1
  • 7
  • 26
0

Try below code which is not overlap each other and limit your text in TextView

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


    <ImageView
        android:id="@+id/flower_picture"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignParentLeft="true"
        android:background="@color/white"
        android:padding="1dp"
        android:scaleType="fitXY" />


    <ImageView
        android:id="@+id/wateredbutton"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:background="@color/white"
        android:scaleType="fitXY" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/wateredbutton"
        android:layout_toRightOf="@+id/flower_picture"
        android:orientation="horizontal"
        android:weightSum="10">

        <TextView
            android:id="@+id/label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="5"
            android:ellipsize="end"
            android:maxLines="1" />

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="5"
            android:ellipsize="end"
            android:maxLines="1" />

    </LinearLayout>
</RelativeLayout>
Pranav Darji
  • 744
  • 3
  • 13
  • Perfiect, it did the trick, with the ellipsize still working, and no length or weight so the pictures don't scale. Thanks a lot ! – Pierre Feb 01 '17 at 12:06