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

①  字体设置:

修改代码 :  GridViewActivity.java

priceTv为 TextView

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

设置宽度:

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

也可:

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

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

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

 上述价格处理有问题

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));
 }

posted @ 2013-11-06 17:18  一个学渣  阅读(381)  评论(0编辑  收藏  举报

 

CSDNGitHub 联系邮箱:aikongmeng@gmail.com


Copyright 2008-2019 Government All Rights Reserved