CardView内部的TextView未显示在Recyclerview上

时间:2017-09-28 14:53:52

标签: android android-recyclerview android-cardview

我在recyclerview项目布局中的 cardview 中有两个textview。当我点击recyclerview项目, textview 2 要展开并再次点击时,它必须被折叠。但是没有显示textview 2。

这是我的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/th_root_cardview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="6dp"
    android:padding="10dp">

    <LinearLayout
        android:id="@+id/item_lay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:orientation="vertical"
        android:padding="5dp"
        android:weightSum="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">


            <TextView
                android:id="@+id/th_date"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="0.25"
                android:gravity="center_horizontal"
                android:padding="2dp"
                android:text="23 Sep" />


            <TextView
                android:id="@+id/th_detail_original"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="0.5"
                android:gravity="center_horizontal"
                android:maxLines="2"
                android:padding="3dp"
                android:text="Cash transfer to other account " />


            <TextView
                android:id="@+id/th_amount"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="0.25"
                android:gravity="center_horizontal"
                android:padding="2dp"
                android:text="MMK 23,000" />
        </LinearLayout>

        <TextView
            android:id="@+id/th_detail_expand"
            android:layout_width="181dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center_horizontal"
            android:maxLines="2"
            android:padding="3dp"
            android:text="Sub Content"
            android:visibility="visible" />

    </LinearLayout>


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

适配器点击方法如下:

       transactionCardView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {


                    System.out.println("--->" + arrayList.get(getLayoutPosition()).getThTitle().length());

                    if (arrayList.get(getLayoutPosition()).getThContent().length() > 10) {
                        if ((count % 2) == 0) {
                            System.out.println("--->" + "IF");

                            transactionDetail.setVisibility(View.VISIBLE);
                            transactionDetailExpand.setVisibility(View.GONE);
                            mIsViewExpanded = true;

//                            setTextAnimation(view, transactionCardView);

                            setAnimation();

                        } else {
                            System.out.println("--->" + "ELSE ");
                            transactionDetail.setVisibility(View.VISIBLE);
                            transactionDetailExpand.setVisibility(View.VISIBLE);
                            mIsViewExpanded = false;
                            setAnimation();
//                            setTextAnimation(view, transactionCardView);

                        }
                        count++;
                    }
                }
            });

setAnimation()方法:

    private void setAnimation() {
            if (transactionDetailExpand.isShown()) {
                transactionDetailExpand.startAnimation(animationUp);

                CountDownTimer countDownTimerStatic = new CountDownTimer(COUNTDOWN_RUNNING_TIME, 16) {
                    @Override
                    public void onTick(long millisUntilFinished) {
                    }

                    @Override
                    public void onFinish() {
                        transactionDetailExpand.setVisibility(View.GONE);
                    }
                };
                countDownTimerStatic.start();

//                holder.showMore.setText(context.getString(R.string.show));
//                holder.showMore.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.arrow_down, 0);
            } else {
                transactionDetailExpand.setVisibility(View.VISIBLE);
                transactionDetailExpand.startAnimation(animationDown);

//                holder.showMore.setText(context.getString(R.string.hide));
//                holder.showMore.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.arrow_up, 0);
            }
        }

0 个答案:

没有答案