Skip to content

Commit

Permalink
优化位置的计算方式
Browse files Browse the repository at this point in the history
  • Loading branch information
MZCretin committed Sep 28, 2018
1 parent 8cc4bfc commit 9460d96
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ShowInRecyclerViewActivity extends AppCompatActivity {
private boolean flag = true;
private String content;

private String yourText = "我所认识的中国,强大、友好。@奥特曼 “一带一路”经济带带动了沿线国家的经济发展,促进我国与他国的友好往来和贸易发展,可谓“双赢”。http://www.baidu.com 自古以来,中国以和平、友好的面孔示人。汉武帝派张骞出使西域,开辟丝绸之路,增进与西域各国的友好往来。http://www.baidu.com 胡麻、胡豆、香料等食材也随之传入中国,汇集于中华美食。@RNG 漠漠古道,驼铃阵阵,这条路奠定了“一带一路”的基础,让世界认识了中国。";
private String yourText = "我所认识的中国,强大、友好我所认识的中国,强大、友好。@奥特曼 “一带一路”经济带带动了沿线国家的经济发展,促进我国与他国的友好往来和贸易发展,可谓“双赢”。http://www.baidu.com 自古以来,中国以和平、友好的面孔示人。汉武帝派张骞出使西域,开辟丝绸之路,增进与西域各国的友好往来。http://www.baidu.com 胡麻、胡豆、香料等食材也随之传入中国,汇集于中华美食。@RNG 漠漠古道,驼铃阵阵,这条路奠定了“一带一路”的基础,让世界认识了中国。";

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
android:paddingTop="10dp"
android:text="特别:在RecyclerView中的使用(ListView类似)"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<LinearLayout
android:id="@+id/ll_recyclerview"
Expand Down Expand Up @@ -77,7 +77,7 @@
android:paddingTop="10dp"
android:text="1、正常带链接和@用户,没有展开和收回功能"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_01"
Expand All @@ -99,7 +99,7 @@
android:paddingTop="10dp"
android:text="2、正常带链接,不带@用户,有展开和收回功能,有切换动画"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_02"
Expand All @@ -125,7 +125,7 @@
android:paddingTop="10dp"
android:text="3、正常不带链接,不带@用户,有展开和收回功能,有切换动画"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_03"
Expand All @@ -152,7 +152,7 @@
android:paddingTop="10dp"
android:text="4、正常带链接和@用户,有展开和收回功能,有切换动画"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_04"
Expand All @@ -177,7 +177,7 @@
android:paddingTop="10dp"
android:text="5、正常带链接和@用户,有展开和收回功能,没有切换动画"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_05"
Expand All @@ -202,7 +202,7 @@
android:paddingTop="10dp"
android:text="6、正常带链接和@用户,有展开,没有收回功能"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_06"
Expand All @@ -227,7 +227,7 @@
android:paddingTop="10dp"
android:text="7、正常带链接和@用户,有展开,有收回功能,带附加内容(比如时间)"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_07"
Expand All @@ -252,7 +252,7 @@
android:paddingTop="10dp"
android:text="8、正常带链接和@用户,有展开,没有收回功能,带附加内容(比如时间)"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_08"
Expand All @@ -277,7 +277,7 @@
android:paddingTop="10dp"
android:text="9、正常带链接和@用户,有展开,有收回功能,有'展开'和'收起'始终靠右显示的功能"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_09"
Expand All @@ -303,7 +303,7 @@
android:paddingTop="10dp"
android:text="10、正常带链接和@用户,有展开,有收回功能,带自定义规则(解析[标题](规则)并处理,例如对一些字段进行自定义处理,比如文字中的'--习大大' 和 'Gitbub地址')"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_10"
Expand Down Expand Up @@ -349,7 +349,7 @@
android:layout_height="wrap_content"
android:text="《段子乐》是一款集视频,趣图,段子于一身的社区APP"
android:textColor="#666666"
android:textSize="12sp" />
android:textSize="14sp" />
</LinearLayout>

</LinearLayout>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/item_text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
android:lineSpacingExtra="4dp"
android:padding="16dp"
app:ep_need_contract="true"
android:textSize="12sp"
app:ep_need_always_showright="true"
app:ep_need_expand="true" />

</android.support.constraint.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,12 @@ private SpannableStringBuilder dealLink(FormatData formatData, boolean ignoreMor

if (mNeedAlwaysShowRight) {
//计算一下最后一行有没有充满
float emptyWidth = getWidth() - lineWidth - mPaint.measureText(endString);
float lastLineWidth = 0;
for (int i = 0; i < index; i++) {
lastLineWidth += mDynamicLayout.getLineWidth(i);
}
lastLineWidth = lastLineWidth / (index);
float emptyWidth = lastLineWidth - lineWidth - mPaint.measureText(endString);
if (emptyWidth > 0) {
float measureText = mPaint.measureText(Space);
int count = 0;
Expand Down Expand Up @@ -438,7 +443,12 @@ public void updateDrawState(TextPaint ds) {
//计算一下最后一行有没有充满
int index = mDynamicLayout.getLineCount() - 1;
float lineWidth = mDynamicLayout.getLineWidth(index);
float emptyWidth = getWidth() - lineWidth - mPaint.measureText(endString);
float lastLineWidth = 0;
for (int i = 0; i < index; i++) {
lastLineWidth += mDynamicLayout.getLineWidth(i);
}
lastLineWidth = lastLineWidth / (index);
float emptyWidth = lastLineWidth - lineWidth - mPaint.measureText(endString);
if (emptyWidth > 0) {
float measureText = mPaint.measureText(Space);
int count = 0;
Expand Down

0 comments on commit 9460d96

Please sign in to comment.