Static Background in a listView

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

Static Background in a listView

Postby LordElfo » Thu Jan 28, 2010 8:34 pm

Hi.
Someone knows how can i do to have a static background in a listview?

actually. for each textitem in my list i have one background..

Here is my code

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout
  4.  
  5.  xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.  android:layout_width="wrap_content"
  8.  
  9.  android:layout_height="wrap_content"
  10.  
  11.  android:background="@drawable/background"
  12.  
  13. >
  14.  
  15.   <TextView android:id="@+id/nome"
  16.  
  17.    android:layout_width="fill_parent"
  18.  
  19.    android:layout_height="fill_parent"
  20.  
  21.    android:textSize ="20px"
  22.  
  23.  />
  24.  
  25.  
  26.  
  27. </LinearLayout>
  28.  
  29.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Thxs a lot!
LordElfo
Freshman
Freshman
 
Posts: 3
Joined: Sun Jun 07, 2009 6:16 pm

Top

Postby KarlKarlsom » Fri Jan 29, 2010 8:26 pm

For the ListView you should have the 2 xml files. One that provides the layout for the activity. The other one provides the layout of each ListView item.
What you did is to give each item a backround image.
If you give the complete ListView (see my example) it should work. Then the complete ListView has one static background.
Does this solve your problem?

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout
  5.  
  6. xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8. android:layout_height="50px"
  9.  
  10. android:layout_width="fill_parent">
  11.  
  12.         <ImageView
  13.  
  14.         android:id="@+id/ID1"
  15.  
  16.         android:layout_width="32dip"
  17.  
  18.         android:layout_height="32dip">
  19.  
  20.         </ImageView>
  21.  
  22.         <TextView
  23.  
  24.         android:id="@+id/ID2"
  25.  
  26.         android:layout_height="fill_parent"
  27.  
  28.         android:textSize="20px"
  29.  
  30.         android:layout_width="fill_parent" >
  31.  
  32.         </TextView>
  33.  
  34. </LinearLayout>
  35.  
  36.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4.  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.         android:orientation="vertical"
  7.  
  8.         android:layout_width="fill_parent"
  9.  
  10.         android:layout_height="fill_parent">
  11.  
  12.  
  13.  
  14.      <ListView android:id="@id/android:list"
  15.  
  16.               android:layout_width="fill_parent"
  17.  
  18.               android:layout_height="fill_parent"
  19.  
  20.               android:layout_weight="1"
  21.  
  22.               android:drawSelectorOnTop="false"
  23.  
  24.               android:background="@drawable/background"/>
  25.  
  26.  
  27.  
  28.      <TextView android:id="@id/android:empty"
  29.  
  30.               android:layout_width="fill_parent"
  31.  
  32.               android:layout_height="fill_parent"
  33.  
  34.               android:background="#FF0000"
  35.  
  36.               android:text="No data"/>
  37.  
  38.  </LinearLayout>
  39.  
  40.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
KarlKarlsom
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Mon Dec 14, 2009 8:40 pm

Postby LordElfo » Thu Feb 04, 2010 6:12 pm

Hi.
I've changed my layout to use your code.

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


But now appears one line with a compressed img of the background between each line...
Where i missed?

Thxs
LordElfo
Freshman
Freshman
 
Posts: 3
Joined: Sun Jun 07, 2009 6:16 pm

Postby LordElfo » Thu Feb 04, 2010 8:02 pm

Hi it works now..
Thxs a lot.

Im using 2 xml like you said

one for the rows and one for the principal.

thxs!!!
LordElfo
Freshman
Freshman
 
Posts: 3
Joined: Sun Jun 07, 2009 6:16 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests