Tôi đang tìm kiếm thực hiện một danh sách các tài liệu của phong cách này. Làm thế nào tôi có thể làm điều này trên Android? Tôi nên xem những lớp nào? Có bất kỳ thư viện hiện có nào có thể thực hiện việc này dễ dàng không?Làm thế nào tôi có thể thực hiện một thiết kế Vật liệu Mở rộng/Thu Danh sách trên Android?
19
A
Trả lời
1
tôi thực hiện một danh sách như vậy sử dụng thư viện này:
expandable-recycler-view
Có một blog liên quan, nhưng nó đề cập đến một phiên bản cũ:
Expand a RecyclerView in Four Steps
Đó là cơ bản một bộ chuyển đổi nơi bạn có thể cung cấp danh sách các yếu tố cha mẹ có chứa trẻ em. Bạn tiếp tục phải chỉ định hai người giữ cho cha mẹ và con cái. Xem trang của thư viện để biết thêm chi tiết.
class MyChild {
// add data
}
class MyParentListItem implements ParentListItem {
private final List<MyChild> mChildren;
MyParentListItem(List<MyChild> children) {
mChildren = children;
// add other data
}
@Override
public List<MyChild> getChildItemList() {
return mChildren;
}
@Override
public boolean isInitiallyExpanded() {
return false;
}
}
class MyParentViewHolder extends ParentViewHolder {
MyParentViewHolder(View itemView) {
super(itemView);
// get other views with itemView.findViewById(..);
}
}
class MyChildViewHolder extends ChildViewHolder {
MyParentViewHolder(View itemView) {
super(itemView);
// get other views with itemView.findViewById(..);
}
}
public class MyExpandableAdapter extends ExpandableRecyclerAdapter<MyParentViewHolder, MyChildViewHolder> {
private final LayoutInflater mInflater;
public MyExpandableAdapter(List<MyParentListItem> parentItemList, Context context) {
super(parentItemList);
mInflater = LayoutInflater.from(context);
}
@Override
public MyParentViewHolder onCreateParentViewHolder(ViewGroup parentViewGroup) {
final View itemView = mInflater.inflate(R.layout.parent_layout, parentViewGroup, false);
return new MyParentViewHolder(itemView);
}
@Override
public MyChildViewHolder onCreateChildViewHolder(ViewGroup childViewGroup) {
final View itemView = mInflater.inflate(R.layout.child_layout, childViewGroup, false);
return new MyChildViewHolder(itemView);
}
// bind data to holders in the onBind methods
}
5
Có, bạn có thể dễ dàng triển khai nó với thư viện SectionedRecyclerViewAdapter. Có một ví dụ làm việc đầy đủ here.
Về cơ bản bạn tạo ra một lớp phần:
class MySection extends StatelessSection {
String title;
List<String> list;
boolean expanded = true; // true if you want it to be displayed expanded initially
public MySection(String title, List<String> list) {
// call constructor with layout resources for this Section header, footer and items
super(R.layout.section_header, R.layout.section_item);
this.title = title;
this.list = list;
}
@Override
public int getContentItemsTotal() {
return expanded? list.size() : 0;
}
@Override
public RecyclerView.ViewHolder getItemViewHolder(View view) {
// return a custom instance of ViewHolder for the items of this section
return new MyItemViewHolder(view);
}
@Override
public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
MyItemViewHolder itemHolder = (MyItemViewHolder) holder;
// bind your view here
itemHolder.tvItem.setText(list.get(position));
}
@Override
public RecyclerView.ViewHolder getHeaderViewHolder(View view) {
return new SimpleHeaderViewHolder(view);
}
@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
MyHeaderViewHolder headerHolder = (MyHeaderViewHolder) holder;
// bind your header view here
headerHolder.tvItem.setText(title);
// handles the click on the header to toggle the expanded variable
headerHolder.rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expanded = !expanded;
headerHolder.imgArrow.setImageResource(
expanded ? R.drawable.ic_keyboard_arrow_up_black_18dp : R.drawable.ic_keyboard_arrow_down_black_18dp
);
sectionAdapter.notifyDataSetChanged();
}
});
}
}
Sau đó, bạn thiết lập các RecyclerView với các bộ phận của bạn:
// Create an instance of SectionedRecyclerViewAdapter
SectionedRecyclerViewAdapter sectionAdapter = new SectionedRecyclerViewAdapter();
// Create your sections with the list of data for each topic
MySection topic1Section = new MySection("Attractions", attractionsList);
MySection topic2Section = new MySection("Dining", diningList);
// Add your Sections to the adapter
sectionAdapter.addSection(topic1Section);
sectionAdapter.addSection(topic2Section);
// Set up your RecyclerView with the SectionedRecyclerViewAdapter
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(sectionAdapter);
Các vấn đề liên quan
- 1. thiết kế Vật liệu
- 2. Làm thế nào để ghim mở một sideNav trong góc-Vật liệu Thiết kế
- 3. Thiết kế Vật liệu Android Divider Màu
- 4. Hình dạng Thiết kế Vật liệu Android
- 5. Làm thế nào để thực hiện thiết kế Vật liệu Biên đạo các hoạt ảnh trên bề mặt
- 6. Làm thế nào tôi có thể tiêm một thể hiện của danh sách trong mùa xuân?
- 7. Làm thế nào tôi có thể hợp nhất hai bản đồ trên cùng một danh sách?
- 8. Percent màu trong Android cho thiết kế Vật liệu
- 9. Làm cách nào để tôi có thể thực hiện các bài tập trong danh sách hiểu?
- 10. Status Bar Animate Màu trên DrawerLayout - Vật liệu Thiết kế
- 11. Làm thế nào tôi có thể vẽ thiết kế cơ sở dữ liệu của mình?
- 12. Thực hiện một danh sách với phần chia trong android
- 13. GitLab: Làm thế nào tôi có thể vượt qua hiện vật đến một giai đoạn khác?
- 14. Thiết kế thực thể bị thiếu
- 15. Vật liệu Thiết kế Lite không làm việc với Turbolinks
- 16. Làm cách nào để appengine thực hiện truy vấn trên danh sách một cách hiệu quả?
- 17. Làm thế nào để thiết kế một spinner trong Android
- 18. Không thể nhập Thư viện Thiết kế Vật liệu trong studio android
- 19. Trong Bash, làm thế nào tôi có thể biết liệu mình hiện đang ở một thiết bị đầu cuối
- 20. Làm thế nào tôi có thể thiết kế trực quan một thành phần trong C++ Builder?
- 21. Làm thế nào tôi có thể thiết kế một hệ thống cache bằng PDO và memcached?
- 22. Làm thế nào tôi có thể phát hiện khi nào các cửa sổ mới được mở và/hoặc có danh sách các cửa sổ đang mở?
- 23. Làm thế nào tôi có thể bọc chặt một Cột vật dụng trong Thẻ?
- 24. Làm thế nào bạn có thể đảo ngược thiết kế một tệp tiết kiệm nhị phân?
- 25. Ng-admin: làm cách nào tôi có thể tạo danh sách mẫu tùy chỉnhXem thực thể?
- 26. Có thiết kế Android nào có thể vẽ được không?
- 27. Emulator Android: Làm thế nào tôi có thể nhận được một danh sách các dịch vụ đang chạy
- 28. Python: Làm cách nào tôi có thể kế thừa từ loại danh sách được tích hợp?
- 29. Android Danh sách mở rộng
- 30. Góc thiết kế vật liệu góc trên md-list> md-item
Bạn đã tìm thấy một giải pháp cho điều này, những gì thư viện bạn đã kết thúc sử dụng? Tôi hiện đang sử dụng [này] (https://github.com/HeinrichReimer/material-drawer) nhưng tìm kiếm các mục collapsible như ảnh chụp màn hình của bạn – Mendhak