引用:http://blog.csdn.net/xyz_fly/article/details/9146395#comments
微信朋友圈中,如果好友发表的文字过长,会自动收缩起来,底下有提示,当点击“显示更多”时才会展开。
首先定义布局文件(很简单,不解释):
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/desc_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4.0dip" android:gravity="center_vertical" android:textColor="#ff000000" android:textSize="14.0dip" /> <TextView android:id="@+id/desc_op_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4.0dip" android:gravity="center" android:singleLine="true" android:textColor="#ff576b95" android:textSize="14.0dip" android:visibility="gone" /> </LinearLayout>
文字:
<string name="desc_shrinkup">收起</string> <string name="desc_spread">显示更多</string>
public class CollapsibleTextView extends LinearLayout implements OnClickListener { /** default text show max lines */ private static final int DEFAULT_MAX_LINE_COUNT = 2; private static final int COLLAPSIBLE_STATE_NONE = 0; private static final int COLLAPSIBLE_STATE_SHRINKUP = 1; private static final int COLLAPSIBLE_STATE_SPREAD = 2; private TextView desc; private TextView descOp; private String shrinkup; private String spread; private int mState; private boolean flag; public CollapsibleTextView(Context context, AttributeSet attrs) { super(context, attrs); shrinkup = context.getString(R.string.desc_shrinkup); spread = context.getString(R.string.desc_spread); View view = inflate(context, R.layout.collapsible_textview, this); view.setPadding(0, -1, 0, 0); desc = (TextView) view.findViewById(R.id.desc_tv); descOp = (TextView) view.findViewById(R.id.desc_op_tv); descOp.setOnClickListener(this); } public CollapsibleTextView(Context context) { this(context, null); } public final void setDesc(CharSequence charSequence, BufferType bufferType) {
desc.setText(charSequence, bufferType);
mState = COLLAPSIBLE_STATE_SPREAD;
flag = false;
requestLayout();
} @Override public void onClick(View v) { flag = false; requestLayout(); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (!flag) { flag = true; if (desc.getLineCount() <= DEFAULT_MAX_LINE_COUNT) { mState = COLLAPSIBLE_STATE_NONE; descOp.setVisibility(View.GONE); desc.setMaxLines(DEFAULT_MAX_LINE_COUNT + 1); } else { post(new InnerRunnable()); } } } class InnerRunnable implements Runnable { @Override public void run() { if (mState == COLLAPSIBLE_STATE_SPREAD) { desc.setMaxLines(DEFAULT_MAX_LINE_COUNT); descOp.setVisibility(View.VISIBLE); descOp.setText(spread); mState = COLLAPSIBLE_STATE_SHRINKUP; } else if (mState == COLLAPSIBLE_STATE_SHRINKUP) { desc.setMaxLines(Integer.MAX_VALUE); descOp.setVisibility(View.VISIBLE); descOp.setText(shrinkup); mState = COLLAPSIBLE_STATE_SPREAD; } } } }
效果图:
源码:
引用:http://blog.csdn.net/xyz_fly/article/details/9146395#comments
相关推荐
仿微信显示更多文字的View,可以参见博客效果图
android 实现仿微信通讯录android 实现仿微信通讯录android 实现仿微信通讯录android 实现仿微信通讯录android 实现仿微信通讯录android 实现仿微信通讯录android 实现仿微信通讯录android 实现仿微信通讯录android ...
Android应用源码之高仿微信
Android 完美高仿的微信源码.rar
Android安卓仿微信最新版源码 微信APP源码
微信小程序 仿微信DEMO (源码)微信小程序 仿微信DEMO (源码)微信小程序 仿微信DEMO (源码)微信小程序 仿微信DEMO (源码)微信小程序 仿微信DEMO (源码)微信小程序 仿微信DEMO (源码)微信小程序 仿微信DEMO (源码)微信...
安卓Android源码——仿微信popupwindow.zip
微信小程序源码 仿微信DEMO(学习版)微信小程序源码 仿微信DEMO(学习版)微信小程序源码 仿微信DEMO(学习版)微信小程序源码 仿微信DEMO(学习版)微信小程序源码 仿微信DEMO(学习版)微信小程序源码 仿微信DEMO(学习版)...
完全仿微信的android源码、基本实现微信所有基础功能...
一个仿微信界面和功能的android源码
Android源码之仿微信即时聊天应用
微信小程序仿豆瓣电影源码微信小程序仿豆瓣电影源码微信小程序仿豆瓣电影源码微信小程序仿豆瓣电影源码微信小程序仿豆瓣电影源码微信小程序仿豆瓣电影源码微信小程序仿豆瓣电影源码微信小程序仿豆瓣电影源码微信小...
Android 超高仿微信图片选择器完整实例Android 超高仿微信图片选择器完整实例Android 超高仿微信图片选择器完整实例Android 超高仿微信图片选择器完整实例Android 超高仿微信图片选择器完整实例Android 超高仿微信...
本项目是一个基于安卓的仿微信项目源码,IM通信部分是基于环信的SDK开发的。 对于个人开发者或者小企业来说,做IM用第三方的也是一种趋势吧,毕竟自己整一套可供运营使用的IM系统几乎是不切实际的(技术门槛和维护...
android仿微信后台聊天
android应用源码仿微信用户引导页源码.zip源码资源下载android应用源码仿微信用户引导页源码.zip源码资源下载
Android 应用项目开发源码 参考和学习使用
ANDROID 仿微信 界面 源码 开源
Android应用源码仿微信聊天项目源码。服务器php端代码已经一起打包了。