Android TextView文字超出一屏不能顯示其它的文字 解決方案

來源:互聯網
上載者:User

標籤:

在android上面讓TextView 過多的文字實現有捲軸,之前想簡單了以為設定TextView的屬性就可以實現,結果還是需要ScrollView配合使用,才能達到捲軸的效果有兩種方式實現,

一種是代碼寫java的layout:

01.RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(80,80);  02.//初始化捲軸控制項  03.ScrollView scrollView =new ScrollView(this);  04.scrollView.setScrollContainer(true);  05.scrollView.setFocusable(true);  06.//初始化文字控制項  07.TextView textView = new TextView(this);  08.textView.setHorizontallyScrolling(true);  09.textView.setText("哈哈哈,\n哈哈哈");  10.  11.scrollView.addView(textView);  12.main_view.addView(scrollView, param);  

另一種則用layout.xml來實現:

 

01.<ScrollView   02.           android:layout_width="fill_parent"   03.           android:layout_height="fill_parent"   04.           android:scrollbars="vertical"   05.           android:fadingEdge="vertical">  06.         07.           <TextView  08.                  android:id="@+id/textView"  09.                  android:layout_width="wrap_content"  10.                  android:layout_height="wrap_content"  11.                  android:text="Demo"  12.                  android:textSize="15sp"/>  13.     </ScrollView>  

 

Android TextView文字超出一屏不能顯示其它的文字 解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.