android - Contents in ListView not centered -
my app retrieves user details db , displays in listview. contents displayed in listview not formatted properly.
this how layout rendered:
this layout file activity:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:paddingbottom="16dp" android:paddingleft="16dp" android:paddingright="16dp" android:paddingtop="16dp" tools:context=".leaderboard" > <linearlayout android:id="@+id/column" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <textview android:id="@+id/column_header1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.2" android:text="@string/strlboardheaderrank" android:textcolor="#f00" android:textsize="24sp" /> <textview android:id="@+id/column_header2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.6" android:text="@string/strlboardheadername" android:layout_gravity="center" android:textcolor="#f00" android:textsize="24sp" /> <textview android:id="@+id/column_header3" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.2" android:text="@string/strlboardheaderscore" android:textcolor="#f00" android:textsize="24sp" /> </linearlayout> <listview android:id="@+id/listview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/column" > </listview> </relativelayout>
the layout file list activity below:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" > <textview android:id="@+id/rank" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.2" android:textcolor="#f00" android:textsize="20sp" /> <textview android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.6" android:textcolor="#f00" android:textsize="20sp" /> <textview android:id="@+id/score" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.2" android:textcolor="#f00" android:textsize="20sp" /> </linearlayout>
add android:gravity="center"
textview
s , layout file list activity textview
s width should 0dp
because of weight property , u should add android:orientation="horizontal"
<textview android:id="@+id/column_header1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.2" android:gravity="center" android:text="strlboardheaderrank" android:textcolor="#f00" android:textsize="24sp" /> <textview android:id="@+id/column_header2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.6" android:gravity="center" android:text="strlboardheadername" android:layout_gravity="center" android:textcolor="#f00" android:textsize="24sp" /> <textview android:id="@+id/column_header3" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.2" android:gravity="center" android:text="strlboardheaderscore" android:textcolor="#f00" android:textsize="24sp" />
layout file list
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:orientation="horizontal" > <textview android:id="@+id/rank" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.2" android:gravity="center" android:textcolor="#f00" android:textsize="20sp" /> <textview android:id="@+id/name" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.6" android:gravity="center" android:textcolor="#f00" android:textsize="20sp" /> <textview android:id="@+id/score" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.2" android:gravity="center" android:textcolor="#f00" android:textsize="20sp" /> </linearlayout>
Comments
Post a Comment