日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

TextView限制行数,点击展开显示全部

發布時間:2024/3/24 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TextView限制行数,点击展开显示全部 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

說明:

? ? TextView內容過長,現在要根據超過10行,就顯示其只能顯示10行,點擊展開就顯示全部。

代碼:

? ? Activity代碼:

????? ? 1、處理TextView

//內容處理tv_content.setText(detailObject.getContent());//先把內容填充if (tv_content.getLineCount() > 10) {//判斷TextView有沒有超過10行tv_content.setMaxLines(10);//超過10行就設置只能顯示10行tv_more.setVisibility(View.VISIBLE);//把展示按鈕顯示出來} else {tv_more.setVisibility(View.GONE);//沒有超過10行,就把展示展示按鈕隱藏}

? ?? ? 2、展開按鈕點擊

case R.id.tv_more://內容更多tv_more.setVisibility(View.GONE);//把展開按鈕隱藏tv_content.setMaxLines(Integer.MAX_VALUE);//把TextView行數顯示取消掉break;

?????xml布局:

<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:paddingBottom="5dp"android:paddingLeft="10dp"android:paddingRight="10dp"android:paddingTop="5dp"><TextViewandroid:id="@+id/tv_content"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="內容描述"android:textColor="@color/font_333333"android:textSize="16sp" /><TextViewandroid:id="@+id/tv_more"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="right"android:paddingLeft="10dp"android:paddingTop="5dp"android:text="展開"android:textColor="@color/font_1296db" /></LinearLayout>

總結

以上是生活随笔為你收集整理的TextView限制行数,点击展开显示全部的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。