0

I am designing an app for multiple devices.In that I am using a imageview and using selector i am setting the background image depends on the state.I works fine for all the devices except only one 10 inch device.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true" >

    <LinearLayout
        android:layout_width="145dp"
        android:layout_height="239dp"
        android:layout_marginRight="6dp"
        android:background="@drawable/common_selector_thumbnail_shadow_title_background"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingLeft="5dp"
        android:paddingRight="5dp" >

        <FrameLayout
            android:layout_width="130dp"
            android:layout_height="186dp"
            android:layout_marginTop="5dp"
            android:background="@color/RGB_100_215_216_217" >

            <ImageView
                android:id="@+id/seasonal_favorites_default_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="center"
                android:src="@drawable/tw_noitem_movie" />


        </FrameLayout>

        <TextView
            android:id="@+id/seasonal_favorites_list_text"
            android:layout_width="140dp"
            android:layout_height="43dp"
            android:duplicateParentState="true"
            android:ellipsize="end"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:singleLine="true"
            android:textColor="@drawable/common_selector_thumbnail_shadow_title_textcolor"
            android:textSize="18dp" />
    </LinearLayout>

</FrameLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/thumbnail_title_bg_focus" android:state_focused="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/thumbnail_title_bg_focus" android:state_pressed="true"/>
    <item android:drawable="@drawable/thumbnail_title_bg_focus" android:state_focused="true"/>
    <item android:drawable="@drawable/thumbnail_title_bg"/>

</selector>

Thanks in advance.

AndroidCrazy
  • 334
  • 8
  • 23

5 Answers5

0

Probabilly you have to put in your manifest file: hardwareAccelerated="true"
Try that and let me know if it worked!

Dyna
  • 2,304
  • 1
  • 14
  • 25
  • already it is made as true in my src project.actually i have two project one having src and another having res. – AndroidCrazy Aug 26 '13 at 13:29
  • what do you mean you have two projects? Can you put a screenshot or something so that I could help you? – Dyna Aug 26 '13 at 13:36
0

Use ImageButton there are two methods setBackgroundResource, setImageResource to set resources for button(which one will be pressed) and for image itself

Korniltsev Anatoly
  • 3,676
  • 2
  • 26
  • 37
0

You need to add android:clickable="true" to the LinearLayout or set a OnClickListener there. Otherwise your selector background does not get activated.

sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86
  • i have a parent view top to the linear layout which is having clickable true – AndroidCrazy Aug 26 '13 at 14:14
  • If you want your selector background with value `@drawable/common_selector_thumbnail_shadow_title_background"` being applied, you need to make this *exactly this* element clickable. Or you can set selector background to your parent view. – sergej shafarenka Aug 26 '13 at 14:15
  • Maybe you have another layout of another selector for this device configuration? I mean you have selector under drawables-Xdpi, or layout under layout-vXX or similar, that Android filters them out on that 10" tablet? – sergej shafarenka Aug 26 '13 at 14:35
0

Use ImageButton instead of ImageView to get the selector work.

Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57
0

If you can provide the different states of the image then see this post

Otherwise...

Use a LayerDrawable for the image source. One layer is the actual image, the other layer is a state list selector.

LayerDrawable d = new LayerDrawable(new Drawable[]{getResources().getDrawable(R.drawable.my_image), getResources().getDrawable(R.drawable.my_selector_list)});
imageView.setImageDrawable(d);

Or you can define a layer drawable XML resource and use that in your layout XML.

Community
  • 1
  • 1
Tom Bollwitt
  • 10,849
  • 1
  • 17
  • 11