android 百分數與進度顯示
阿新 • • 發佈:2019-01-04
double percent = entity.getFundraisingMoney() / entity.getInvestmentProjectAll(); //輸出一下,確認你的小數無誤 System.out.println("小數:" + percent); //獲取格式化物件 NumberFormat nt = NumberFormat.getPercentInstance(); //設定百分數精確度2即保留兩位小數 nt.setMinimumFractionDigits(2); //最後格式化並輸出 System.out.println("百分數:" + nt.format(percent)); Log.v("lgq",".......... "+"百分數:" + nt.format(percent)+"...."+entity.getInvestmentProjectAll()+"....."+percent); LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams)holder.jinduteli.getLayoutParams(); //取控制元件textView當前的佈局引數 LinearLayout.LayoutParams linearParamste =(LinearLayout.LayoutParams)holder.jindute.getLayoutParams(); //取控制元件textView當前的佈局參
//只設置長度佔比。還可以設定width 和 height holder.jindute 也就是被設定長度的view必須包裹在LinearLayout中 if (percent>0.1){ linearParams.weight =(float)percent; linearParamste.weight =(float)percent; }else { linearParams.weight =(float)0.05; linearParamste.weight =(float)0.1; } holder.jinduteli.setLayoutParams(linearParams); holder.jindute.setLayoutParams(linearParamste);