10

Some Views are not wrapping it's content when used inside a CardView in Android L. When testing the same code on earlier versions of Android everything works fine. Here is my layout:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/stock_row_height"
card_view:cardCornerRadius="@dimen/default_elevation"
card_view:cardElevation="@dimen/default_elevation"
card_view:cardUseCompatPadding="true">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/logo"
        android:layout_width="@dimen/portals_logo_width"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_margin="@dimen/portals_logo_margin"
        android:adjustViewBounds="true"
        android:src="@drawable/image_placeholder" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toEndOf="@+id/logo"
        android:layout_toRightOf="@+id/logo"
        android:background="@android:color/black"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/holo_green_light"
            android:text="portalAddress.com"
            android:textColor="@android:color/black"
            android:textSize="@dimen/portals_title_text_size" />

        <TextView
            android:id="@+id/description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/holo_blue_light"
            android:text="Sincronizado 04/12/14 às 14:25"
            android:textColor="@color/medium_gray"
            android:textSize="@dimen/portals_description_text_size" />

    </LinearLayout>

</RelativeLayout>

The problem is that the TextView "wrap_content" for height is not working. This is the preview visualisation from Android Studio:

Android Studio Preview

This is the same layout running on a Samsung Galaxy S5 with Android L:

Samsung Galaxy S5 with Android L

If I try to set a fixed height for both TextView (25dp and 18dp respectively) the parent LinearLayout does not wrap it's content the same way as the TextView.

[Fixed height for TextView][3]

I'm missing something? Don't know what is wrong, because this only happens in Android L.

EDIT: I'm still looking for solutions for this problem.

Birk
  • 126
  • 1
  • 2
  • 9
  • I don't have enough reputation to post 3 links, so here is the address of the last one - [Fixed height for TextView](http://imgur.com/2lMeWak) – Birk Jun 03 '15 at 17:52
  • 2
    Did you find the solution? i'm having same problem. – Apsaliya Aug 22 '16 at 13:41

4 Answers4

3

Making the text views widths to wrap_content instead of match_parent might work. Also you can remove the "+" from @+id/logo in the toEndOf and toRightOf attribute.

prats110892
  • 6,599
  • 1
  • 12
  • 6
  • 1
    Already tried that with no success. The width attribute is working fine, but height is not considering "wrap_content. And thanks for the tip on the "+" sign. – Birk Jun 03 '15 at 19:23
  • can you tell me the version number of the L installed on your S5, is it 20 or 21or 22? and also which version of support library are you using? ( I am assuming api 20 since you mentioned Android L) – prats110892 Jun 04 '15 at 05:51
  • I'm using support version 22.1.0, CompileSdkVersion 22, buildToolsVersion 22.0.1 and targetSdkVersion 22. The S5 android version is 5.0. – Birk Jun 08 '15 at 13:14
0

Try removing android:layout_toEndOf="@+id/logo" from LinearLayout as it positions the start edge of this view to the end of the logo ImageView.

Ajeet
  • 1,540
  • 1
  • 17
  • 30
0

Sometimes the background/src images are the cause of this problem, try using smaller images and convert them to 9P ones.

0

if you have TextView inside try to make
android:layout_width="match_parent"

that's work for me.

rootShiv
  • 1,375
  • 2
  • 6
  • 21
Ibrahim Shara'h
  • 1
  • 1
  • 1
  • 1