2017-07-07 60 views
0

我有一個包含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; 
    } 

} 

回答

0

刪除maxLines="25";這將文本的長度限制爲25行。

+0

不幸的是,這並沒有解決問題。 – Blnpwr

+0

上面的佈局文件沒有錯(雖然有點亂),我只是自己測試了一下。刪除'maxLines =「25」'爲我解決了這個問題,所以一定有其他的東西導致你的問題。發佈放置'Fragment5'的'Activity'佈局文件? – Bryan