Android開發(fā)實現(xiàn)的文本折疊點擊展開功能示例
本文實例講述了Android開發(fā)實現(xiàn)的文本折疊點擊展開功能。分享給大家供大家參考,具體如下:
信息欄,景點介紹,購物信息,進場會使用到文本折疊的方法
實現(xiàn)非常簡單,這里就不哆嗦了
效果如下:

Demo:https://github.com/LonglyWolf/NavigationSystemHLJU
這里用到了三方類庫,在app/gradle添加依賴如下:
//文本過長 點擊展開全部 implementation 'com.ms-square:expandableTextView:0.1.4'
上面的實例是通過adapter就和listView實現(xiàn)的,這里就不搞那么復雜,直接看折疊文本的方法實現(xiàn):
首先是主活動:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// sample code snippet to set the text content on the ExpandableTextView
ExpandableTextView expTv1 = (ExpandableTextView) findViewById(R.id.expand_text_view);
// IMPORTANT - call setText on the ExpandableTextView to set the text content to display
expTv1.setText("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
}
重點在于布局文件的設置:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.ms.square.android.expandabletextview.ExpandableTextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
android:id="@+id/expand_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
expandableTextView:maxCollapsedLines="4"
expandableTextView:animDuration="200">
<TextView
android:id="@id/expandable_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="16sp"
android:textColor="#666666" />
<ImageButton
android:id="@id/expand_collapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_gravity="right|bottom"
android:background="@android:color/transparent"/>
</com.ms.square.android.expandabletextview.ExpandableTextView>
</LinearLayout>
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》及《Android資源操作技巧匯總》
希望本文所述對大家Android程序設計有所幫助。
- android 無須root截圖方案的實現(xiàn)
- Android實現(xiàn)合并生成分享圖片功能
- Android自定義View實現(xiàn)課程表表格
- Android開發(fā)之FloatingActionButton懸浮按鈕基本使用、字體、顏色用法示例
- android關(guān)于按鈕點擊效果實現(xiàn)的方法
- Android判斷json格式將錯誤信息提交給服務器
- android和服務器的URLEncodedUtils亂碼編碼問題的解決方案
- Android開發(fā)之SeekBar基本使用及各種美觀樣式示例
- Android使用Service實現(xiàn)IPC通信的2種方式
- Android Studio三方引用報錯但是項目可以運行的解決方案
相關(guān)文章
通過WIFI(不用數(shù)據(jù)線)連接Android手機調(diào)試
本文主要介紹WIFI 鏈接手機調(diào)試,這里詳細介紹了WIFI 鏈接Android手機實現(xiàn)調(diào)試的過程,有需要的小伙伴可以參考下2016-08-08
Android實現(xiàn)動態(tài)高斯模糊效果示例代碼
這篇文章主要介紹了Android快速實現(xiàn)動態(tài)模糊效果示例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-01-01
Android ScrollView實現(xiàn)橫向和豎向拖動回彈效果
這篇文章主要為大家詳細介紹了Android ScrollView實現(xiàn)橫向和豎向拖動回彈效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-09-09
Android之RecyclerView實現(xiàn)時光軸效果示例
本篇文章主要介紹了Android之RecyclerView實現(xiàn)時光軸效果,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02

