rounded corners for listView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

rounded corners for listView

Postby achie1266 » Thu Dec 17, 2009 3:14 pm

I an trying to create my listview with rounded corners.
So am setting my background rectangle of the listview to have rounded edges

this is my listview layout file
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.                 android:id="@+id/main_list"
  6.  
  7.         android:layout_width="fill_parent"
  8.  
  9.         android:layout_height="fill_parent"
  10.  
  11.         android:orientation="vertical"
  12.  
  13.         android:padding="5dip" >
  14.  
  15.    
  16.  
  17.           <ListView android:id="@android:id/list"
  18.  
  19.                 android:layout_width="fill_parent"
  20.  
  21.                 android:layout_height="wrap_content"
  22.  
  23.                 android:background="@drawable/list_corner_1"
  24.  
  25.                 android:layout_weight="1.0" />
  26.  
  27.           <TextView android:id="@android:id/empty"
  28.  
  29.                 android:layout_width="wrap_content"
  30.  
  31.                 android:layout_height="wrap_content"
  32.  
  33.                 android:text="@string/no_items"/>
  34.  
  35.  
  36.  
  37. </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4

this is the background list_corner_1.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.     android:shape="rectangle">
  6.  
  7.      <gradient
  8.  
  9.         android:startColor="#CCCCFF"
  10.  
  11.         android:endColor="#99CCFF"
  12.  
  13.        android:angle="90"/>
  14.  
  15.     <corners
  16.  
  17.         android:bottomRightRadius="10dp"
  18.  
  19.         android:bottomLeftRadius="10dp"
  20.  
  21.         android:topLeftRadius="10dp"
  22.  
  23.         android:topRightRadius="10dp"/>
  24.  
  25. </shape>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
Right now it does not even recognize the background. It functions as if I did not give ant background at all.
please help me solve this problem if you know hoe to fix it.

Thank you
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Postby achie1266 » Tue Dec 29, 2009 4:33 am

Still trying to solve this.
Can someone help me out.
Thank you.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby sabs » Wed Dec 30, 2009 7:59 am

achie1266 wrote:Still trying to solve this.
Can someone help me out.
Thank you.

Hiii

I tried and finally got the solution for that rounded corners here iam attaching an emulator screenshort in this reply. If you are trying for that only, please check where you have kept the "list_corner_1" xml file, means under which res you have kept that. I have kept that list_corner_1.xml file under res/layout. If your idea is different please elaborately explain your idea so that i can also try for that.

code synaptic

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none">
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@layout/corner" ----> corner is a new xml file like your list_corner_1 i placed under res/layout.
android:scrollbars="none"></ListView>
</LinearLayout>

once again iam telling If your idea is different then please elaborately explain.

Advance Happy new year.

thanks
sabs
Attachments
Screenshot.png
Screenshot.png (173.82 KiB) Viewed 3019 times
sabs
Developer
Developer
 
Posts: 32
Joined: Fri Dec 04, 2009 2:55 pm

Postby achie1266 » Wed Dec 30, 2009 8:45 am

Hey Sabs,

Thanks for the reply..
Your final product[listView] looks like what I needed.
So what did you do in your corner layout?

What I am trying to do is to us the rounded rectangle as the background for the listView. I placed the rounded rectangle in the drawable folder since that is where we keep all our custom shapes. I used that approach for other backgrounds like textviews and it worked. i just don't understand why ListView is not taking that background.

yeah i would very much like to know the solution and go ahead and try it if you want to.
BTW can you also tell me how you did yours.

Thank you.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby sabs » Wed Dec 30, 2009 10:19 am

achie1266 wrote:Hey Sabs,

Thanks for the reply..
Your final product[listView] looks like what I needed.
So what did you do in your corner layout?

What I am trying to do is to us the rounded rectangle as the background for the listView. I placed the rounded rectangle in the drawable folder since that is where we keep all our custom shapes. I used that approach for other backgrounds like textviews and it worked. i just don't understand why ListView is not taking that background.

yeah i would very much like to know the solution and go ahead and try it if you want to.
BTW can you also tell me how you did yours.

Thank you.


Hii

I created one xml file under the res / layout in that file i placed the corner xml code.

This is my actual xml code where my list view is placed.

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

android:scrollbars="none">
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:background="@layout/corner" ---> this is what i created

android:scrollbars="none" android:drawingCacheQuality="auto"></ListView>
</LinearLayout>

This is my corner's xml file which i placed under the res / layout
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor= "#008B8B"
android:endColor="#CCCCFF"

android:angle="360"/>

<corners

android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"
/>
</shape>

Try this and get back to me with results...

with regards
sabs
sabs
Developer
Developer
 
Posts: 32
Joined: Fri Dec 04, 2009 2:55 pm

Postby kamalpreet.singh » Sun Jan 24, 2010 7:30 pm

Hey I am very new to android,

I also had similar requirement, and your post helped me a lot. I've been reading android books, but I didn't got any information on the

Corners tag, and the gradient tag.

Can you help in figuring out where to get such information, I mean one that is not published in a book...

thanks
regards-
Kamalpreet
kamalpreet.singh
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Jan 24, 2010 6:14 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 8 guests