2016-06-02 21 views
7

Tôi chỉ đang tìm kiếm một ví dụ cho bảng mở rộng trong android (Material design).Bảng mở rộng trong Google Material design android

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

Tôi biết chúng tôi có chế độ xem danh sách mở rộng. Nhưng, tôi cần hiển thị một số chế độ xem bố cục bổ sung để mở rộng từng bảng tương tự như chế độ xem Accordian. Làm thế nào chúng ta có thể đạt được điều này trong android?

Trả lời

6

Thử bố cục có thể mở rộng here. Nó có thể có hành vi tương tự như một Accordian

Bao gồm nó để gradle của bạn với compile 'com.github.aakira:expandable-layout:[email protected]' Ví dụ

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

Sau đó, trong mã java của bạn

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(); 
      } 
     }); 

Hy vọng rằng sẽ là hữu ích.

Các vấn đề liên quan