您的位置:首页 > 移动开发 > Android开发

android TextView字体设置最少占多少行. 及其 Java String 字符串操作 . .

2013-11-06 17:18 459 查看
① 字体设置:

修改代码 : GridViewActivity.java

priceTv为 TextView

priceTv.setMaxLines(3);
//当多与7个字fu的时候 , 其余字符不显示..
if (name.length()>=7) {
name  = name.substring(0, 6)+"...";
}
priceTv.setMinLines(3);


设置宽度:

priceTv.setMaxWidth(250);
priceTv.setMinWidth(250);

也可:

priceTv.setEms(250);
priceTv.setEms(250);

截取字符串 : 运行结果是 22.000555

public class TestDemo {
public static void main(String[] args) {
String p = "22.000555000";
while( p.endsWith("0")|| p.endsWith(".")){
p =p.replace(p, p.substring(0, p.length()-1));
}
System.out.println(p);
}
}


上述价格处理有问题

if( p.endsWith(".0")){
p =p.replace(p, p.substring(0, p.length()-2));
} else if(p.endsWith(".00")){
p =p.replace(p, p.substring(0, p.length()-3));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: