如何实现类似Google Play的可折叠视图?

Mih*_*nca 18 android android-layout

我想实现一个可折叠的视图,就像Google Play市场一样.它显示内容中的多个行和箭头,并点击箭头显示整个内容.这是使用ExpandableListView实现的还是有其他解决方案?

屏幕截图附上突出显示我正在寻找的东西.谢谢.在此输入图像描述

War*_*zit 30

有一种更简单的方法:

        final TextView descriptionText = (TextView) view.findViewById(R.id.detail_description_content);
        final TextView showAll = (TextView) view.findViewById(R.id.detail_read_all);
        showAll.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                showAll.setVisibility(View.INVISIBLE);

                descriptionText.setMaxLines(Integer.MAX_VALUE);
            }
        });
Run Code Online (Sandbox Code Playgroud)

XML:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/detail_description_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView
            android:id="@+id/detail_description_content"
            android:maxLines="5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <TextView
            android:id="@+id/detail_read_all"
            android:clickable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

最重要的部分是maxlines和scrollview.这不会给出一个慢动画(这将是一个更复杂的出价),而是一个即时开放效果.