CardView中的可滚动TextView

时间:2016-04-18 20:39:47

标签: android scrollbar android-scrollview android-cardview

如果文本太大而无法容纳,我试图在CardView中实现TextView垂直滚动。

不幸的是,此代码无法按预期工作。你能帮帮我吗?

         

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="5dp">

        <ImageView
            android:id="@+id/imageViewBookImage"
            android:layout_width="80dp"
            android:layout_height="120dp" />

        <TextView
            android:id="@+id/textViewBookName_EN"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="BookName_EN" />


            <ScrollView
                android:id="@+id/textAreaScroller"
                android:layout_width="fill_parent"
                android:layout_height="173px"
                android:layout_x="0px"
                android:layout_y="25px"
                android:scrollbars="vertical">

                <TextView
                    android:id="@+id/textViewBookDescription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:lines="7"
                    android:text="Book Description" />
            </ScrollView>

    </LinearLayout>

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

1 个答案:

答案 0 :(得分:0)

Activity中将此行添加到TextView

TextView tv;
...

tv = (TextView) findViewById(R.id.textViewBookDescription);
tv .setMovementMethod(new ScrollingMovementMethod());
相关问题