android - 使textview在recyclerView中展开

标签 android xml android-layout textview android-recyclerview

我有一个看起来像 RecyclerView 的项目:

enter image description here

如果用户点击帮助图标,我想在中间显示项目的描述,扩展项目的高度,如下所示:

enter image description here

我尝试了不同的方法,但我无法让它工作,我尝试设置父级的高度(但我认为这不是一个好方法,因为它应该根据有多少文本有描述来自动获得大小) 但它不起作用,使布局包装内容也不起作用,因为它是底部对齐父级的 RelativeLayout,任何帮助都会很棒

布局

<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" />

最佳答案

尝试布局为:

<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>

关于android - 使textview在recyclerView中展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36618907/

相关文章:

java - Android - fragment 内的 RecyclerView - NullPointerException

android - 如何在android的默认浏览器选择列表中添加我的浏览器?

Java 类到 XSD

php - 如何将 XML 字符串回显到 HTML 页面以进行调试?

java - 有没有办法在 Android Studio 中使用像 colorPrimary 这样的样式主题颜色作为我的项目背景 intsted of @color/"whateverColorYouWant"

Android Spinner 工具栏样式

Android 软键盘无法在 webView 中打开`

android - 当行宽等于 TextView 的宽度时,为什么 TextView 会断行

android - 使用屏幕锁定调用应用程序

android - 如何将 map 放入 PagerAdapter?是否可以?