0

I am developing an application in which i am using a custom list view. The XML code is as follows :

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

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="15sp"
        android:background="@android:color/white" >

        <ListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:divider="#000000"
            android:dividerHeight=".5sp" >
        </ListView>
    </RelativeLayout>

</RelativeLayout>

And my custom adapter XML is :

<?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/textview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingTop="75sp"
        android:paddingBottom="75sp"
        android:gravity="center"
        android:textSize="20sp"
        android:textColor="@android:color/white" />

</RelativeLayout>

But my out put is not like what i needed. I needed vertical padding of text which i given in adapter textview in XML.

My out put is:

output

I need space from top and bottem of text in text view which is in adapter of list view.

I tried from .java file also as :

textView.setPadding(0, 75, 0, 75);

but of no use.

I need output like :

enter image description here

Please guide me what should i do now.

Manoj Fegde
  • 4,786
  • 15
  • 50
  • 95

2 Answers2

0

You don't need top and bottom then, check this:

<?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/textviewn_company_clsa"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="75dp"
        android:text="asdf"
        android:textColor="@android:color/white"
        android:textSize="20sp" />

</RelativeLayout>  

For the custom layout, inside your TextView, use marginTop and marginBottom (or layout_margin)which will give you space outside the TextView's container.

Padding provides the space within your container. For your ListView item, you need the space outside each row/item also.

Check:
Android beginner difference between padding and margin
Difference between a View's Padding and Margin

android:paddingTop="75sp"
android:paddingBottom="75sp"  

And

android:layout_margin="15sp"  
android:dividerHeight=".5sp" 

Unit needs to be in "dp"..:

android:paddingTop="75dp"
android:paddingBottom="75dp" 

And

android:layout_margin="15dp"  
android:dividerHeight=".5dp"  

For your ref:
What is the difference between "px", "dp", "dip" and "sp" on Android?
http://www.prandroid.com/2013/03/differences-between-px-dip-dp-and-sp.html

Community
  • 1
  • 1
Pararth
  • 8,114
  • 4
  • 34
  • 51
  • I done with the changes. But my out put is same. No effect of changes. Please guide me. – Manoj Fegde Mar 10 '14 at 06:31
  • Please have a look on my edit to post. I pasted output what i need. – Manoj Fegde Mar 10 '14 at 06:39
  • In other words, margin and padding are the same: they make space between your thing and the others, but padding fills the space with your view and margin leaves the space empty. – MichalH Apr 22 '17 at 12:58
0

Use this :

<?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="60dp" >

    <TextView 
        android:id="@+id/textviewn_company_clsa"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:textSize="20sp"
        android:textColor="@android:color/white" />

</RelativeLayout>
Harshit Rathi
  • 1,862
  • 2
  • 18
  • 25