1

I have an item of RecyclerView that looks :

enter image description here

If user click on the help icon, I want to show a description of the item in the middle expanding the height of the item like this:

enter image description here

I tryed differents ways but I cant make it work, I tryed to set the height of the parent ( but I dont think this is a good approach, since it should get the size automattically in fuction of how many text have the description) but it doesnt work, make layout wrap content doesnt work either since it is a RelativeLayout with alignparent bottom, any help will be great

Layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:animateLayoutChanges="true"
android:background="@drawable/stroke_shop_adapter"
android:orientation="vertical">


<TextView
    android:id="@+id/nombre"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_gravity="center"
    android:layout_margin="5dp"
    android:layout_marginTop="10dp"
    android:layout_toRightOf="@+id/img"
    android:layout_toLeftOf="@+id/ayuda"
    android:gravity="center|top"
    android:text="@string/level"
    android:textColor="#fff"
    android:textSize="15sp" />

<ImageView

    android:id="@+id/img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_gravity="center"
    android:src="@drawable/cubo" />

<TextView
    android:id="@+id/descripcion"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/img"
    android:layout_toLeftOf="@+id/ayuda"
    android:layout_below="@+id/separador1"
    android:layout_above="@+id/coste"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:gravity="center"
    android:text=""
    android:textColor="#fff"
    android:textSize="14sp" />

<ImageView
    android:id="@+id/ayuda"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="10dp"
    android:src="@drawable/ayuda_icon"/>


<TextView
    android:id="@+id/coste"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/ayuda"
    android:gravity="center"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginBottom="10dp"
    android:text="100$"
    android:textColor="#fff"
    android:textSize="13sp" />

<View
    android:id="@+id/separador1"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_below="@id/nombre"
    android:layout_toRightOf="@+id/img"
    android:layout_toLeftOf="@+id/ayuda"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginBottom="2dp"
    android:background="#00c6ff"/>


<TextView

    android:id="@+id/nivel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="5dp"
    android:layout_toRightOf="@+id/img"
    android:layout_alignParentBottom="true"
    android:text="Level: 5/7"
    android:textColor="#fff"
    android:textSize="13sp" />

<TextView

    android:id="@+id/maxNivel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@id/separador1"
    android:layout_marginBottom="5dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="5dp"
    android:text=""
    android:textColor="#fff"
    android:textSize="17sp" />

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
D4rWiNS
  • 2,585
  • 5
  • 32
  • 54

2 Answers2

2

Try layout as:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorBlack"
                android:orientation="vertical">

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:src="@mipmap/ic_launcher"/>

    <ImageView
        android:id="@+id/ayuda"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:src="@mipmap/ic_launcher"/>

    <TextView
        android:id="@+id/nombre"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:layout_marginTop="10dp"
        android:layout_toLeftOf="@+id/ayuda"
        android:layout_toRightOf="@+id/img"
        android:gravity="center|top"
        android:text="Level"
        android:textColor="#fff"
        android:textSize="15sp"/>

    <View
        android:id="@+id/separador1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@id/nombre"
        android:layout_marginBottom="2dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_toLeftOf="@+id/ayuda"
        android:layout_toRightOf="@+id/img"
        android:background="#00c6ff"/>

    <TextView
        android:id="@+id/descripcion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/separador1"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_toLeftOf="@+id/ayuda"
        android:layout_toRightOf="@+id/img"
        android:text="content desc content desc content desc content desc content desc content desc content desc "
        android:textColor="#fff"
        android:gravity="center_horizontal"
        android:textSize="14sp"/>

    <TextView
        android:id="@+id/nivel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/descripcion"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@+id/img"
        android:text="Level: 5/7"
        android:textColor="#fff"
        android:textSize="13sp"/>

    <TextView
        android:id="@+id/coste"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/descripcion"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_toLeftOf="@+id/ayuda"
        android:gravity="center"
        android:text="100$"
        android:textColor="#fff"
        android:textSize="13sp"/>


</RelativeLayout>
Hello World
  • 2,764
  • 1
  • 11
  • 23
1

In that case you can use Expandable-RecyclerView

Download the latest AAR via Maven:

<dependency>
  <groupId>com.levelupstudio</groupId>
  <artifactId>expandable-recyclerview</artifactId>
  <version>1.0.1</version>
</dependency>

or Gradle:

compile 'com.levelupstudio:expandable-recyclerview:1.0.1'

Other option is to use

You can try with ExpandableHeightListView

enter image description here

enter image description here Add ExpandableHeightListView instead of ListView in your xml files:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView
            android:id="@+id/expandable_listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="8dp">
        </com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView>
</ScrollView>

Add this to your build.gradle:

repositories {
    mavenCentral()
}

dependencies {
  compile 'com.github.paolorotolo:expandableheightlistview:1.0.0'
}
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142