在Cardview中显示文本,不适合屏幕
问题描述:
我有一个包含CardView的布局。我添加了滚动查看,我在Textview中添加了android:scrollable=vertical
,我添加了mytxtview.setMovementMethod(new ScrollingMovementMethod());
在Cardview中显示文本,不适合屏幕
没有任何作品!我在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;
}
}
答
删除maxLines="25"
;这将文本的长度限制为25行。
不幸的是,这并没有解决问题。 – Blnpwr
上面的布局文件没有错(虽然有点乱),我只是自己测试了一下。删除'maxLines =“25”'为我解决了这个问题,所以一定有其他的东西导致你的问题。发布放置'Fragment5'的'Activity'布局文件? – Bryan