0

myoutputimage

Hi My textview is not moved into next line,Even i set maxlenght,maxsize also,Need to set imageview width based height,Sorry for my poor english

Here is my xml what i tried,

<RelativeLayout
        android:id="@+id/rlTopview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/proimg"
            android:layout_width="200dp"
            android:layout_height="160dp"
            android:background="@drawable/categoriesicon"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/txtcom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/proimg"
            android:layout_marginLeft="5dp"
            android:maxEms="23"
            android:maxLines="2"
            android:scrollHorizontally="false"
            android:singleLine="false"
            android:text="Learn and Understanding \Node JS"
            android:textColor="@color/colorPrimaryBlack"
            android:textSize="18dp" /></RelativeLayout>
  • I think you need to change android:text="Learn and Understanding \Node JS" to android:text="Learn and Understanding \n Node JS" – Pulkit Sep 11 '17 at 14:56

2 Answers2

0

Your <ImageView> tag has a defined width of 200dp. If what you want is for each card to be exactly 200dp wide, the image to fill the card, and the text below it to wrap if it's longer than 200dp, make these changes:

  • Change your RelativeLayout's width from match_parent to 200dp
  • Change your ImageView's width from 200dp to match_parent
  • Change your TextView's width from wrap_content to match_parent
Ben P.
  • 52,661
  • 6
  • 95
  • 123
-1

First of all please remove the @+id from the TextView it should be only @id. Then back to your problem you have three approaches, either to set the ImageView to full width like this

<RelativeLayout
android:id="@+id/rlTopview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/proimg"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="@drawable/categoriesicon"
android:scaleType="centerCrop" />

<TextView
android:id="@+id/txtcom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/proimg"
android:layout_marginLeft="5dp"
android:maxEms="23"
android:maxLines="2"
android:scrollHorizontally="false"
android:singleLine="false"
android:text="The Complete Banking\nCourses"
android:textColor="@color/colorPrimaryBlack"
android:textSize="18dp" />
</RelativeLayout>

or to set the TextView alignment to the ImageView like this

<ImageView
android:id="@+id/proimg"
android:layout_width="200dp"
android:layout_height="160dp"
android:background="@drawable/categoriesicon"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/txtcom"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/proimg"
android:layout_marginLeft="5dp"
android:maxEms="23"
android:maxLines="2"
android:scrollHorizontally="false"
android:singleLine="false"
android:text="The Complete Banking\nCourses"
android:textColor="@color/colorPrimaryBlack"
android:textSize="18dp" />

third one will be like this

<TextView
    android:id="@+id/txtcom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/proimg"
    android:align_right="@id/proimg"
    android:align_left="@id/proimg"
    android:scrollHorizontally="false"
    android:singleLine="false"
    android:text="The Complete Banking\nCourses"
    android:textColor="@color/colorPrimaryBlack"
    android:textSize="18dp" />
Yamen Nassif
  • 2,416
  • 2
  • 24
  • 48