用了android的各种布局,发现每种布局的居中,对齐方式都不一样,需要自己屡次尝试,甚是苦恼
给同样在苦恼中的人晒下TableLayout居中的方式
这是一个即将被我充斥到另外一个
<ListView android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/detail">
</ListView>
里面去的Table,其实实现它的每单元格内容居中很简单,给它的上一级设置android:gravity="center"即可,还有个问题,需去掉下一级所有跟居中有关的属性
(之前没去掉,上级的属性都没生效了,奇怪?),代码如下:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow android:gravity="center">
<TextView
android:layout_height="wrap_content"
android:layout_width="113dp"
android:textSize="16dip"
android:textColor="@color/gray5"
android:id="@+id/clsname">
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="103dp"
android:textSize="16dip"
android:textColor="@color/gray5"
android:id="@+id/salesamt">
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textSize="16dip"
android:textColor="@color/gray5"
android:id="@+id/profitamt">
</TextView>
</TableRow>
</TableLayout>
PS:最后一个TextViev里android:layout_width="match_parent"和父容器的android:layout_width="match_parent"搭配在一起为了
最后一列自适应屏幕分辨率