android - How to vertically centre elements in a ListView? -
i have number of switch elements laid out in listview. they're appearing follows:

but need them vertically centred, e.g.

i'm using following axml definition each list item:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/widget32" android:layout_width="fill_parent" android:layout_height="wrap_content"> <switch android:id="@+id/switchoutput" android:layout_width="250dp" android:layout_height="wrap_content" android:text="[output name]" android:gravity="center_vertical" /> <imagebutton android:id="@+id/imgtime" android:background="@null" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/datetime" android:scaletype="fitcenter" android:layout_alignparentright="true" /> </relativelayout> i thought android:gravity="center_vertical" enough them appear correctly, doesn't appear working. need switches vertically centred in each list item?
add android:layout_centervertical="true"... center child vertically within parent...
note:- parent layout must relativelayout..
op edit: correctly centred layout now:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/widget32" android:layout_width="fill_parent" android:layout_height="wrap_content"> <switch android:id="@+id/switchoutput" android:layout_width="250dp" android:layout_height="wrap_content" android:text="[output name]" android:layout_centervertical="true" /> <imagebutton android:id="@+id/imgtime" android:background="@null" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/datetime" android:scaletype="fitcenter" android:layout_alignparentright="true" /> </relativelayout>
Comments
Post a Comment