xml - android:gravity not changing the position of the text in a TextView -
i writing code activity has table contains 2 rows(see screenshot). text in 2 rows in center(not textview).
however, setting android:gravity = "center"
or android:gravity = "center_horizontal"
not affect text @ all.
missing?
activity_game.xml:
<linearlayout 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="@android:color/white" android:orientation="horizontal" android:padding="16dp" tools:context=".mainactivity"> <tablelayout android:id="@+id/tl1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <tablerow android:id="@+id/tr_header_p1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/table_row_bg" android:padding="5dp"> <textview android:id="@+id/player1_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="player 1" android:textcolor="#000000" android:textsize="24sp" /> </tablerow> <tablerow android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/table_row_bg" android:padding="5dp"> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/table_cell_bg" android:gravity="center" android:text="guess" android:textcolor="#000000" android:textsize="16sp" /> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/table_cell_bg" android:gravity="center" android:text="bulls" android:textcolor="#000000" android:textsize="16sp" /> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="cows" android:textcolor="#000000" android:textsize="16sp" /> </tablerow> </tablelayout> <tablelayout android:id="@+id/tl2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <tablerow android:id="@+id/tr_header" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/table_row_bg" android:padding="5dp"> <textview android:id="@+id/player2_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="player 2" android:textcolor="#000000" android:textsize="24sp" /> </tablerow> <tablerow android:id="@+id/tr_header2" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/table_row_bg" android:padding="5dp"> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/table_cell_bg" android:gravity="center" android:text="guess" android:textcolor="#000000" android:textsize="16sp" /> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/table_cell_bg" android:gravity="center" android:text="bulls" android:textcolor="#000000" android:textsize="16sp" /> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="cows" android:textcolor="#000000" android:textsize="16sp" /> </tablerow> </tablelayout>
try should work,
add android:gravity="center"
@+id/tr_header_p1
, @+id/tr_header
like,
<tablerow android:id="@+id/tr_header_p1" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:padding="5dp">
and
<tablerow android:id="@+id/tr_header" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:padding="5dp">
this might helps you
edit 1
or need mention android:layout_weight="1"
textview.
<textview android:id="@+id/player2_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_weight="1" android:text="player 2" android:textcolor="#000000" android:textsize="24sp" />
Comments
Post a Comment