android之标签icon在文本多行背后或首次位置显示
来源:互联网 发布:macair windows 编辑:程序博客网 时间:2024/06/16 22:03
private void drawImageViewDone(int width, int height) {try{textWidth = content_top_tv.getTextSize();paint.setTextSize(textWidth);// 一行字体的高度int lineHeight = content_top_tv.getLineHeight();// 可以放多少行int lineCount = (int) height / lineHeight;// int lineCount = 4;// 一行的宽度float rowWidth = mScreenWidth - width - content_top_tv.getPaddingLeft()- content_top_tv.getPaddingRight();// 一行可以放多少个字int columnCount = (int) (rowWidth / textWidth);// 总共字体数等于 行数*每行个数count = lineCount * columnCount;if(text.length() < count){content_top_tv.setText(text);content_bottom_tv.setVisibility(View.GONE);return;}// 一个TextView中所有字符串的宽度和(字体数*每个字的宽度)textTotalWidth = (float) ((float) count * textWidth);measureText();content_top_tv.setText(text.substring(0, count));// 检查行数是否大于设定的行数,如果大于的话,就每次减少一个字符,重新计算行数与设定的一致while (content_top_tv.getLineCount() > lineCount) {count -= 1;content_top_tv.setText(text.substring(0, count));}//content_bottom_tv.setPadding(0, lineCount * lineHeight - height, 0, 0);//gz此处修改将原有布局中marginTop=8dp 删除,setPadding顶部取的值由 -8 改为 8, 从而解决textview顶部被砍掉的错乱问题content_bottom_tv.setPadding(0, height-lineCount * lineHeight , 0, 0);content_bottom_tv.setText(text.substring(count));}catch(Exception e){e.printStackTrace();}}
xml:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/preg_export_bg" android:orientation="horizontal" android:padding="6dip" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/epic" android:layout_width="90dip" android:layout_height="90dip" android:layout_alignParentRight="true" android:layout_marginRight="6dip" android:layout_marginTop="5dip" android:background="@drawable/default_user_head" /> <TextView android:id="@+id/content_top_tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="6dip" android:layout_marginTop="6dip" android:layout_toLeftOf="@+id/epic" android:lineSpacingExtra="4dip" android:textColor="@color/gray3" android:text="打算发送到发送到发送到发送到发送到发送到发送到发的说法送到发送到asdfasdf发的说法gadf " android:textSize="16sp" /> <TextView android:id="@+id/content_bottom_tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/epic" android:layout_marginLeft="6dip" android:layout_marginRight="6dip" android:lineSpacingExtra="4dip" android:textColor="@color/gray3" android:text="打算发送到发送到发送到发送到发送到发送到发送到发的说法" android:textSize="16sp" /> </RelativeLayout> </LinearLayout>
demo :点击打开链接
0 0
- android之标签icon在文本多行背后或首次位置显示
- android之文本前面或后面多标签
- android:如何改变TabActivity标签大小 显示ICON
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示 .
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android开发之PopupWindow在指定位置上显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- android 之popupWindow 在指定位置上的显示
- 【C++】拷贝构造函数之浅复制与深复制
- 创业App对接三方支付辛酸史
- Android Studio导入Android源码
- Android requires compiler compliance level 5.0 or 6.0. Found '1.8' instead. 解决办法
- 网络时延——发送时延和传播时延
- android之标签icon在文本多行背后或首次位置显示
- 记录一下使用百度Ueditor副编辑器的过程及碰到的问题
- hadoop实例分析之WordCount单词统计分析
- 踩过的坑-WebView加载卡住或者加载不出来的问题
- 庆祝我的Hexo博客搭建成功-nianhua110.github.io
- 单链表中环的检测
- 最小路径覆盖问题(二分图)
- asm基础——计算机的原码和补码
- android 如何在广播里面更新 UI