android
開發群中才得知
justifytextview
借用一下原圖:
/issues/1
)中作者也告知了如何解決,只是githup**中未更新,這裡的**已做出了修改):
import android.content.context;
import android.graphics.canvas;
import android.graphics.paint;
import android.text.layout;
import android.text.staticlayout;
import android.text.textpaint;
import android.util.attributeset;
import android.widget.textview;
/**
* @author ccheng
* @date 3/18/14
*/ public class justifytextview extends textview
@override
protected void onlayout(boolean changed, int left, int top, int right,
int bottom)
@override
protected void ondraw(canvas canvas)
paint.fontmetrics fm = paint.getfontmetrics();
int textheight = (int) (math.ceil(fm.descent - fm.ascent));
textheight = (int) (textheight * layout.getspacingmultiplier() + layout
.getspacingadd());
//解決了最後一行文字間距過大的問題
for (int i = 0; i < layout.getlinecount(); i++) else
} else
mliney += textheight;
} }
private void drawscaledtext(canvas canvas, int linestart, string line,
float linewidth)
int gapcount = line.length() - 1;
int i = 0;
if (line.length() > 2 && line.charat(0) == 12288
&& line.charat(1) == 12288)
float d = (mviewwidth - linewidth) / gapcount;
for (; i < line.length(); i++)
} private boolean isfirstlineofparagraph(int linestart, string line)
private boolean needscale(string line) else
} }
補充知識
全形: 指乙個字元占用兩個標準的字元位置
半形: 指乙個字元占用乙個標準的字元位置
漢字字元和規定了全形的英文本元以及國際gb2312-80中得圖形符號和特殊字元都是全形字符,系統命令是不用全形字符的。
通常的英文本母、數字鍵、符號鍵都是半形的。
全形佔兩個位元組,半形佔乙個位元組。
android textview換行問題
應用中 textview包含年月日的時候 在一行內不能顯示完整時 文字內容會自動換行。這裡使用網上大家使用的方法,比如半形轉全形 過濾特殊字元等等都無效。最終的解決辦法是在年月日這裡加空格。eg 2013年11月28日20時22分 最終替換為 2013 年 11 月 28 日 20時22分 個人理解...
android textview功能列表
1 顯示富文字 url 文字大小 顏色 字型 autolink all phone web email map none string str i love china charsequeence cq html.fromhtml str textview.settext cq textview.s...
Android TextView屬性XML詳解
android ems 設定textview的寬度為n個字元的寬度。android maxems 設定textview的寬度為最長為n個字元的寬度。與ems同時使用時覆蓋ems選項。android minems 設定textview的寬度為最短為n個字元的寬度。與ems同時使用時覆蓋ems選項。an...