1

I have a ListView in my project that set a pattern in item's background

my xml drawable

temp_listview_sample.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <layer-list>
            <item>
                <shape>
                     <gradient android:angle="270" android:endColor="#00000000" android:startColor="#00000000" />
                     <stroke android:width="2dp" android:color="#CCA48300" />
                     <corners android:radius="5.1dp" />
                     <padding android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp" />
                </shape>
            </item>
            <item>
                <bitmap android:gravity="center" android:src="@drawable/bg_list1" android:tileMode="repeat" />
            </item>
        </layer-list>
    </item>

    <item android:state_enabled="true">
        <layer-list>
             <item>
                <shape android:shape="rectangle">
                    <gradient android:angle="270" android:endColor="#00000000" android:startColor="#00000000" />
                    <stroke android:width="2dp" android:color="#ff000000" />
                    <corners android:radius="5.1dp" />
                    <padding android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp" />
                </shape>
            </item>
            <item>
                <bitmap android:gravity="center" android:src="@drawable/bg_list" android:tileMode="repeat" />
            </item>
        </layer-list>
    </item>
</selector>

and my code in listview adapter

sample_main_menu_layout_item = (ViewGroup) row1.findViewById(R.id.sample_main_menu_layout_item);
        sample_main_menu_layout_item.setBackgroundResource(R.drawable.temp_listview_sample);

but tilemode not works in below android 4

image

excuse me for bad speaking english ;)

also I used these but dont work https://stackoverflow.com/a/11153248

https://stackoverflow.com/a/9500334

I have a selector and 2 layer-list and 2 bitmap in one xml

can anyone help me for fix it?


EDIT:

my xml file for listview items

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/sample_main_menu_layout_item"
    android:layout_width="fill_parent"
    android:layout_height="80dip"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:background="@drawable/temp_listview_sample" >
    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="top"
        android:orientation="vertical"
        android:layout_marginRight="4dip">
    <TextView
            android:id="@+id/txt_message_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/message_count_shape"
            android:text="0"
            android:maxHeight="20dp"
           android:layout_gravity="top"
            android:gravity="top"
            android:textColor="#ffffffff"
            android:textSize="12dip"
            android:layout_marginTop="2dip"
            android:layout_marginLeft="4dip"
            android:visibility="visible" />
    <ImageView
            android:id="@+id/img_next"
            android:layout_width="30dip"
            android:layout_height="30dip"
            android:layout_gravity="center_vertical"
            android:background="@drawable/ic_previous_item" />
   </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:layout_marginRight="8dip"
        android:gravity="center_vertical|center_horizontal"
        android:orientation="vertical" 
        android:layout_marginTop="4dip"
        android:layout_marginBottom="4dip" >
       <TextView
            android:id="@+id/txt_text_menu"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textColor="#ffffffff"
            android:textSize="20dip"
            android:layout_gravity="right|center_vertical" 
            android:gravity="right"/>
     </LinearLayout>
        <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_marginRight="8dip"
        android:layout_marginLeft="4dip" >
        <ImageView
        android:id="@+id/img_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:scaleType="centerInside"/>
     </LinearLayout> 
</LinearLayout>
14
  • can you please show the xml that you use per listview item? "row1" the inflated/recycled view of the each row that you use in the getView() method, right? Commented Nov 22, 2013 at 23:25
  • that right, row1=convertView in getview, yes put xml in below post Commented Nov 23, 2013 at 1:38
  • I cant answer to my question :D my xml file is this link uplooder.net/cgi-bin/… Commented Nov 23, 2013 at 1:55
  • I think you've put the wrong xml file, since there is no view there with the id of "sample_main_menu_layout_item" . is it also possible you don't use the "viewHolder" design pattern, as shown on the google IO lecture "the world of listView" ? Commented Nov 23, 2013 at 8:02
  • I dont think because it works correct in android 4, but there is a bug in android 1- 2 - 3, in two up link it solves that it is include selector and bitmap but my xml code is include selector and layer-list and bitmap and it doesn't work for me , this link stackoverflow.com/questions/7412430/… Commented Nov 23, 2013 at 11:36

1 Answer 1

1

I copy my bitmap xml for each view and problem solve Greatly

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.