今天项目需要实现一个点击展开收缩的功能,网上搜索找了个适合自己的,稍微修改了下适合项目本身需求的。
只是做记录,需要的可以参考。
不废话直接上代码。
首先main布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/head" android:orientation="vertical" tools:context="com.foldtext.MainActivity"> <LinearLayout android:id="@+id/lin_tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/backdrop_top_style" android:orientation="horizontal"> <TextView android:id="@+id/hello1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:maxLines="2" android:padding="10dp" android:text="标题" /> <TextView android:id="@+id/textview_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="点击向下展开" /> <ImageView android:id="@+id/img_shrink"