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>
Community
  • 1
  • 1
  • 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? – android developer Nov 22 '13 at 23:25
  • that right, row1=convertView in getview, yes put xml in below post – user2736455 Nov 23 '13 at 01:38
  • I cant answer to my question :D my xml file is this link http://www.uplooder.net/cgi-bin/dl.cgi?key=e95f189d98c5b69c4fb19c1801ff781f – user2736455 Nov 23 '13 at 01: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" ? – android developer Nov 23 '13 at 08: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 http://stackoverflow.com/questions/7412430/statelistdrawable-and-tiled-bitmap/11153248#11153248 – user2736455 Nov 23 '13 at 11:36
  • i don't understand what you are saying. it seems you didn't understand me. the xml file you've shown of the layout that you use per row doesn't have the id of "sample_main_menu_layout_item" , so you are clearly doing something wrong here, or you've put the wrong file. – android developer Nov 23 '13 at 12:14
  • sorry, I sent the wrong file, but it is like this, set it in next post – user2736455 Nov 23 '13 at 21:55
  • i've edited your original question to hold the xml file (nothing else was added/modified/removed). you can delete what you've created as an answer, and please try to avoid it next time. anyway, can you please try to explain what doesn't work exactly? maybe show images of what you want to have and what you get? – android developer Nov 23 '13 at 22:59
  • tnx , excuse me for bad speak english , I want my items be same this http://www.uploadax.com/images/54731931654434793472.jpg , but in android 2 or 3 it show same this http://axgig.com/images/14726213446653891097.jpg , how fix it? I know it is a bug in android 1 and 2 and 3, also it show correct in android 4 – user2736455 Nov 23 '13 at 23:15
  • why do you have a gradient with complete transparent color ? is it a trick to put the content inside the shape? – android developer Nov 23 '13 at 23:53
  • yes, because i dont need to gradient color but I need only to strok and raduce corners , and a bitmap fill into it , now I problem with this on android lower 4 ,According to this way http://stackoverflow.com/questions/7412430/statelistdrawable-and-tiled-bitmap/11153248#11153248 Can you change it So that work for me? – user2736455 Nov 24 '13 at 00:23
  • i don't know why you get this weird behavior. have you tried using a relativeLayout instead of multiple linearLayouts ? also why did you use weight (and of 2), yet you didn't set the width to 0px ? have you also tried Lint (the button that looks like a checkbox with a "V" in it)? maybe it could give you a hint about what's wrong. – android developer Nov 24 '13 at 06:26
  • my friend , I dont have problem with xml layout and my problem is tileMode in "temp_listview_sample.xml" that android:tileMode="repeat" dont work! According to my Search it is a bug in old android and Some people have suggested solutions but i think it have to Some change that work for me but I dont know how do it – user2736455 Nov 24 '13 at 10:43
  • ok, sorry. i'm not aware of this issue and i don't know how to fix it. just thought it might help to try other things. – android developer Nov 24 '13 at 10:53

1 Answers1

1

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