对齐行数据考虑的ListView小数点 [英] Align row data considering decimal point in listview
本文介绍了对齐行数据考虑的ListView小数点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含列和多行像
I have a table format containing columns and multiple rows like
M.wt
D.wt
Cs.wt
12.000
2.340
0.997
下面M.wt,D.wt和Cs.wt是标题栏和值表明,我不能够对准值以下考虑其他小数点之一,我得到像
Here M.wt ,D.wt and Cs.wt is the heading column and the values are has shown,i am not able to align the values considering decimal point one below the other,i am getting like
12.000
2.566
5.666
我的布局就像是code是像
My layout is like code is like
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:id="@+id/textView21"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="#000000"
android:textStyle="bold"
android:typeface="serif"
/>
<TextView
android:id="@+id/textView22"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="#000000"
android:textStyle="bold"
android:typeface="serif"
/>
</LinearLayout>
如何处理好这一点,应该在布局或Java文件来处理?
我的屏幕居然是像这样:
How to handle this,it should be handle in layout or java file ? My screen is actually like so:
推荐答案
您需要的是您要设置为的TextView
对于像3小数点格式化文本以下
You need to format the text that is you are setting to the TextView
for the 3 decimal points like below
mwt = 0.2f;
textView2 = (TextView)findViewById(R.id. textView2);
textView2.setText(String.format("%.3f",mwt));
dwt = 0.1f;
textView21 = (TextView)findViewById(R.id.textView21);
textView2.setText(String.format("%.3f",dwt));
重力属性添加作为结束,你的文本视图会
Add the gravity property as end and your text view will be
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold"
android:typeface="serif" />
这篇关于对齐行数据考虑的ListView小数点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文