【问题标题】:Expansion panels in Google Material design androidGoogle Material design android中的扩展面板
【发布时间】:2016-06-02 14:37:13
【问题描述】:

我只是在寻找 android 中扩展面板的示例(材料设计)。

https://www.google.com/design/spec/components/expansion-panels.html

我知道我们有可扩展的列表视图。但是,我需要在扩展每个面板时显示一些额外的布局视图,类似于 Accordian 视图。我们如何在android中实现这一点?

【问题讨论】:

    标签: android material-design


    【解决方案1】:

    尝试可扩展布局 here 。它可以具有与 Accordian 相同的行为

    使用 compile 'com.github.aakira:expandable-layout:1.5.1@aar' 将其包含到您的 gradle 中 示例

    <LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/accordian_header"
        android:clickable="true">
        <TextView
            android:id="@+id/accordian_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:textColor="#333"
            android:textStyle="bold"
            android:text="Title" />
    
        <ImageButton
            android:id="@+id/down_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_margin="8dp"
            android:src="@android:drawable/arrow_down_float" />
    </RelativeLayout>
    <com.github.aakira.expandablelayout.ExpandableLinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="14dp"
            android:paddingRight="14dp"
            android:paddingBottom="14dp"
            android:orientation="vertical"
            android:id="@+id/content"
            app:ael_expanded="false"
            app:ael_duration="500"
            app:ael_orientation="vertical">
    <!--add your content here -->
      </com.github.aakira.expandablelayout.ExpandableLinearLayout>
    
    </LinearLayout>
    

    然后在你的 java 代码

    ExpandableLinearLayout content=(ExpandableLinearLayout) itemView.findViewById(R.id.content);
    RelativeLayout header=(RelativeLayout) itemView.findViewById(R.id.accordian_header);
    
    //to toggle content
    header.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    content.toggle();
                }
            });
    

    希望对您有所帮助。

    【讨论】:

    • 为什么这个expandableList在第一次点击时不展开?我使用了三个不同的库,但都出现了同样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    • 2019-03-17
    • 2020-07-24
    • 1970-01-01
    相关资源
    最近更新 更多