3

我完全熟悉 ExpandableRecyclerview 或 ExpandableLayout 但我有一个有点独特的设计,我正在寻求帮助来实现这个实现。

我正在附加设计 要实施的设计

当用户单击图像中显示的箭头时,CardView Recyclerview 应该在评论按钮和响应部分之间展开或膨胀一个 recyclerview。怎么做。我已经尝试过来自 ThoughtBot 的 ExpandableRecyclerview 和 ExpandableListView 所有这些组件都向父级添加了一个子级。

我正在使用 Thoughtbot 的 ExpandableRecyclerview, com.thoughtbot.expandablerecyclerview

我的适配器如下所示。

public class ReviewRecyclerAdapter extends ExpandableRecyclerViewAdapter<ReviewViewHolder, CommentsViewHolder> {

private Context context;

public ReviewRecyclerAdapter(Context context,List<? extends ExpandableGroup> groups) {
    super(groups);
    this.context = context;

}


@Override
public ReviewViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.list_item_review, parent, false);
    return new ReviewViewHolder(view);
}

@Override
public CommentsViewHolder onCreateChildViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.list_item_comments, parent, false);
    return new CommentsViewHolder(view);

}

@Override
public void onBindChildViewHolder(CommentsViewHolder holder, int flatPosition, ExpandableGroup group, int childIndex) {
    final CommentsModel comments = ((ReviewsModel) group).getItems().get(childIndex);
    holder.setSubTitletName(comments.getComment());
}

@Override
public void onBindGroupViewHolder(ReviewViewHolder holder, int flatPosition, ExpandableGroup group) {
    holder.setGenreTitle(context, group);

}

}

// 查看持有人

 public class ReviewViewHolder extends GroupViewHolder {

    private TextView titleName;
    private ImageView arrow;
    private ImageView icon;

    public ReviewViewHolder(View itemView) {
        super(itemView);
        titleName = (TextView) itemView.findViewById(R.id.list_item_genre_name);
        arrow = (ImageView) itemView.findViewById(R.id.list_item_genre_arrow);
    }

    public void setGenreTitle(Context context, ExpandableGroup title) {
        if (title instanceof ReviewsModel) {
            titleName.setText(title.getTitle());
            if (((ReviewsModel) title).getReview()!= null && !((ReviewsModel) title).getReview().isEmpty()){

            }
        }
    }

    @Override
    public void expand() {
        animateExpand();
    }

    @Override
    public void collapse() {
        animateCollapse();
    }

    private void animateExpand() {
        RotateAnimation rotate =
                new RotateAnimation(360, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(300);
        rotate.setFillAfter(true);
        arrow.setAnimation(rotate);
    }

    private void animateCollapse() {
        RotateAnimation rotate =
                new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(300);
        rotate.setFillAfter(true);
        arrow.setAnimation(rotate);
    }

}

 public class CommentsViewHolder extends ChildViewHolder {

private TextView subTitleTextView;

public CommentsViewHolder(View itemView) {
    super(itemView);
    subTitleTextView = (TextView) itemView.findViewById(R.id.subtitle);
}

public void setSubTitletName(String name) {
    subTitleTextView.setText(name);
}

}

//查看布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="24dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


            <RelativeLayout
                android:id="@+id/review_details"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/list_avatar"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="10dp"
                    android:src="@drawable/profile_placeholder" />


                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_marginStart="16dp"
                    android:layout_toEndOf="@+id/list_avatar">

                    <TextView
                        android:id="@+id/list_item_genre_name"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="10dp"
                        android:maxEms="15"
                        android:text=" Guru natha"
                        android:textStyle="bold"
                        android:layout_alignParentTop="true" />

                    <TextView
                        android:id="@+id/textView8"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:maxEms="15"
                        android:text=" From Mg Road"
                        android:layout_alignStart="@+id/list_item_genre_name"
                        android:layout_marginStart="10dp"
                        android:layout_below="@+id/list_item_genre_name" />
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentTop="true">

                    <TextView
                        android:id="@+id/days"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:layout_marginStart="10dp"
                        android:maxEms="15"
                        android:text=" 3 Days ago"
                        android:textSize="8sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/count"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignStart="@+id/days"
                        android:layout_below="@+id/days"
                        android:maxEms="15"
                        android:text=" 448 Views"
                        android:textSize="8sp" />
                </RelativeLayout>

            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/review_details"
                android:layout_margin="20dp">

                <TextView
                    android:id="@+id/review"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_marginStart="10dp"
                    android:maxEms="15"
                    android:text="Review"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginStart="10dp"
                    android:maxEms="15"
                    android:text="Rating"
                    android:textStyle="bold" />


                <View
                    android:id="@+id/lineytf"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_below="@+id/review"
                    android:background="@color/black" />

                <TextView
                    android:layout_marginTop="10dp"
                    android:id="@+id/review_conetent"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignStart="@+id/lineytf"
                    android:layout_below="@+id/lineytf"
                    android:maxLines="3"
                    android:maxEms="15"
                    android:text="@string/lorem_ipsum" />


            </RelativeLayout>

            <RelativeLayout
                android:layout_marginLeft="30dp"
                android:layout_marginRight="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/content">

                <TextView
                    android:id="@+id/response"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_marginStart="30dp"
                    android:maxEms="15"
                    android:text="Response (2)"
                    android:textStyle="bold" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginStart="10dp"
                    android:maxEms="15"
                    android:layout_above="@+id/line2"
                    android:src="@drawable/white_r_arrow"
                    android:text="arrow"
                    android:textStyle="bold"
                    android:id="@+id/list_item_genre_arrow" />


                <View
                    android:id="@+id/line2"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_below="@+id/response"
                    android:background="@color/black" />

                <!--Add expandable views-->


                <Button
                    android:id="@+id/commentsbutton"
                    android:textSize="12sp"
                    android:textAllCaps="false"
                    android:text="Comments"
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_below="@+id/line2"
                    android:layout_toStartOf="@+id/button2" />

                <Button
                    android:textSize="12sp"
                    android:textAllCaps="false"
                    android:text="56"
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_below="@+id/list_item_genre_arrow"
                    android:layout_alignParentEnd="true"
                    android:id="@+id/button2" />


            </RelativeLayout>
        </RelativeLayout>
    </android.support.v7.widget.CardView>
</RelativeLayout>

//评论布局

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="40dp">

    <ImageView
        android:id="@+id/list_item_genre_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginLeft="70dp"
        android:layout_alignParentRight="true"
        android:src="@drawable/android" />

    <TextView
        android:id="@+id/subtitle"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="100dp"
        android:gravity="center_vertical"
        tools:text="SubTitle" />

</FrameLayout>

当前截图:当前实施

如果有,请拍摄最接近的解决方案。

4

0 回答 0