2

I have a listview in xml with both layout_width and layout_height as fill_parent.

I am using default layout supplied by android as android.R.layout.simple_list_item_1.But as it is default supplied by android i cannot make alignment in center.Default alignment is left-side. Anyway to do that.I know i can make my own textview and give as R.layout.my_textView.But anyway to make listview items in center with that defaule layout.

Sephy
  • 50,022
  • 30
  • 123
  • 131
Android Killer
  • 18,174
  • 13
  • 67
  • 90

4 Answers4

0

can you put up your layout? the error may be that your missing "android:gravity="center""

KaSiris
  • 407
  • 3
  • 13
  • no eroor is there.Red my question."android:gravity="center"" is not availablke in listview.Even if i am giving it it is not working. – Android Killer Feb 14 '12 at 11:58
  • @AndroidKiller http://stackoverflow.com/questions/5305632/android-centering-items-in-a-listview I don't think you have to do it with your ListView item but with your layout which you inflate in the getView() of your adapter for the row. – Sergey Benner Feb 14 '12 at 12:01
  • guys just read my question 2 times at least please and then give answer. – Android Killer Feb 14 '12 at 12:11
  • @AndroidKiller this link might enlighten you http://stackoverflow.com/questions/6304608/what-is-android-r-id-text1 practically you cannot do without overriding it elsewhere and how it looks like http://www.netmite.com/android/mydroid/frameworks/base/core/res/res/layout/simple_list_item_1.xml – Sergey Benner Feb 14 '12 at 12:21
0

Use a RelativeLayout and set android:layout_centerHorizontal="true"

UPDATE: This is the layout for a row

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/label"
        android:text="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
Toni Toni Chopper
  • 1,833
  • 2
  • 20
  • 29
0

You could override part of the layout of the system TextView in the getView method of your adapter by setting the gravity, margin or anything else there when the view is rendered.

Sephy
  • 50,022
  • 30
  • 123
  • 131
0

for textview alignment in center you can create a custom row xml for creating custom row xml follow that document http://devblogs.net/2011/01/04/custom-listview-with-image-using-simpleadapter/

akshat
  • 19
  • 7