android - How to vertically centre elements in a ListView? -


i have number of switch elements laid out in listview. they're appearing follows:

enter image description here

but need them vertically centred, e.g.

enter image description here

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...

layout_centervertical

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

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -