From d366a778cfac000f8fee0fecd91069782fa007e0 Mon Sep 17 00:00:00 2001 From: 112233 Date: Thu, 14 Mar 2019 10:30:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8=E6=9C=89=E4=BA=9B?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E4=B8=8A=E5=81=B6=E5=B0=94=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E7=99=BD=E5=B1=8F=EF=BC=8C=E5=8A=A0=E8=BD=BD=E4=B8=8D?= =?UTF-8?q?=E5=87=BA=E5=86=85=E5=AE=B9=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/modules.xml | 3 ++ README.md | 23 +++++++++----- .../ExpandableTextView.java | 30 +++++++++++++++++-- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/.idea/modules.xml b/.idea/modules.xml index f9d13f7..3c5d16a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,8 +3,11 @@ + + + \ No newline at end of file diff --git a/README.md b/README.md index edd6335..3fd697b 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,21 @@ **实现类似微博内容,@用户,链接高亮,@用户和链接可点击跳转,可展开和收回的TextView。觉得好用别忘了star哦,你的star是对我最大的激励** ### 更新日志 + ++ 2019-03-14 10:25:57更新,修复在有些手机上偶尔会出现白屏,加载不出内容的情况,依赖版本请使用tag版本1.5.3 + + ```java + implementation 'com.github.MZCretin:ExpandableTextView:v1.5.3' + ``` + + 2018-10-09 17:20:45 更新,新增对展开和回收的点击事件监听,依赖版本请使用tag版本v1.5.2 - ``` + + ```java implementation 'com.github.MZCretin:ExpandableTextView:v1.5.2' ``` + 2018-09-28 09:37:28 更新,优化了将"展开"和"收回"固定最右显示时中间空格数量的计算方式,依赖版本请使用tag版本v1.5.1,[查看说明](#新特性额外说明) - ``` + ```java implementation 'com.github.MZCretin:ExpandableTextView:v1.5.1' ``` @@ -17,19 +25,19 @@ + 在demo中添加自定义设置显示文本的功能,您可以自己设置需要显示的文本,然后查看对应的显示效果; + 新增了"展开"和"收回"按钮始终居右的功能,具体效果请查看效果图的第9条,依赖版本请使用tag版本v1.5,[查看说明](#新特性额外说明) - ``` + ```java implementation 'com.github.MZCretin:ExpandableTextView:v1.5' ``` + 2018-09-22 23:32:16 更新,新增自定义规则解析,具体效果请查看效果图的第10条,依赖版本请使用tag版本v1.4,[查看说明](#新特性额外说明) - ``` + ```java implementation 'com.github.MZCretin:ExpandableTextView:v1.4' ``` + 2018-09-21 11:51:24 更新,优化了demo的代码逻辑和注释 + 2018-09-21 08:45:13 更新,修复了自定义设置展开和收回内容无效的问题,依赖请使用tag版本v1.3.1 - ``` + ```java implementation 'com.github.MZCretin:ExpandableTextView:v1.3.1' ``` @@ -44,12 +52,13 @@ + 2018-09-03 17:39:56 修复一些bug,链接sheSpan位置错误,未生成release,等待下次修复其他bug一起打tag依赖包,使用请本地依赖使用 + 2018-08-31 17:31:56 优化设置padding对宽度造成的影响,依赖请使用tag版本v1.2 - ``` + ```java implementation 'com.github.MZCretin:ExpandableTextView:v1.2' ``` + 2018-08-31 11:21:22 在V1.0的基础上进行了优化,依赖请使用tag版本v1.1 - ``` + + ```java implementation 'com.github.MZCretin:ExpandableTextView:v1.1' ``` diff --git a/expandabletextviewlibrary/src/main/java/com/ctetin/expandabletextviewlibrary/ExpandableTextView.java b/expandabletextviewlibrary/src/main/java/com/ctetin/expandabletextviewlibrary/ExpandableTextView.java index 7689f06..40229ee 100644 --- a/expandabletextviewlibrary/src/main/java/com/ctetin/expandabletextviewlibrary/ExpandableTextView.java +++ b/expandabletextviewlibrary/src/main/java/com/ctetin/expandabletextviewlibrary/ExpandableTextView.java @@ -191,6 +191,9 @@ public class ExpandableTextView extends AppCompatTextView { */ private int mEndExpandTextColor; + //是否AttachedToWindow + private boolean isAttached; + public ExpandableTextView(Context context) { this(context, null); } @@ -203,6 +206,19 @@ public ExpandableTextView(Context context, @Nullable AttributeSet attrs, int def super(context, attrs, defStyleAttr); init(context, attrs, defStyleAttr); setMovementMethod(LocalLinkMovementMethod.getInstance()); + addOnAttachStateChangeListener(new OnAttachStateChangeListener() { + @Override + public void onViewAttachedToWindow(View v) { + if (isAttached == false) + doSetContent(); + isAttached = true; + } + + @Override + public void onViewDetachedFromWindow(View v) { + + } + }); } private void init(Context context, AttributeSet attrs, int defStyleAttr) { @@ -296,7 +312,17 @@ public void setEndExpendContent(String endExpendContent) { */ public void setContent(final String content) { mContent = content; + if (isAttached) + doSetContent(); + } + /** + * 实际设置内容的 + */ + private void doSetContent() { + if (mContent == null) { + return; + } currentLines = mLimitLines; if (mWidth <= 0) { @@ -312,11 +338,11 @@ public void setContent(final String content) { @Override public void run() { retryTime++; - setContent(content); + setContent(mContent.toString()); } }); } else { - setRealContent(content); + setRealContent(mContent.toString()); } }