在Cardview中显示文本,不适合屏幕

时间:2017-07-07 18:50:50

标签: android xml

我有一个包含CardView的布局。我添加了Scrollview,我在Textview中添加了android:scrollable=vertical,我添加了mytxtview.setMovementMethod(new ScrollingMovementMethod());

没有工作!我在textview中有一个非常大的文本,它不适合屏幕,我看不到整个文本,请帮助我。这是我的布局,请帮帮我。

  <?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:tag="cards main container">

        <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_viewfrag5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            card_view:cardBackgroundColor="#A9E2F3"
            card_view:cardCornerRadius="10dp"
            card_view:cardElevation="5dp"
            card_view:cardUseCompatPadding="true"
            >

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

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="12dp"
                    android:layout_weight="2"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbarfrag5"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.96"
                        android:background="#A9E2F3"
                        android:minHeight="?attr/actionBarSize"
                        android:theme="?attr/actionBarTheme">

                        <ImageView
                            android:id="@+id/imageViewfrag5"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_margin="5dp"
                            android:layout_weight="1"
                            android:src="@drawable/testbild"
                            android:tag="image_tag" />

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


                    <TextView
                        android:id="@+id/textViewNamefrag5"
                        android:layout_width="340dp"
                        android:maxLines="25"
                        android:scrollbars="vertical"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:layout_marginTop="10dp"
                        android:text="here is a very very very long text that does not fit into the screen"
                        android:layout_weight="0.96"
                        android:textAppearance="?android:attr/textAppearanceLarge" />

                </LinearLayout>
            </LinearLayout>

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

    </LinearLayout>

</ScrollView>

编辑:Java代码

public class Fragment5 extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        ViewGroup rootView = (ViewGroup) inflater.inflate(
                R.layout.fragmentdescrip5, container, false);


        TextView mytxtview = (TextView) rootView.findViewById(R.id.textViewNamefrag5);
        mytxtview.setMovementMethod(new ScrollingMovementMethod());



        return rootView;
    }

}

1 个答案:

答案 0 :(得分:0)

删除maxLines="25";这会将文本的长度限制为25行。