Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FrameLayout foreground with selectors

I have a FrameLayout which i want to apply foreground drawable for it via selector , i am trying to implement "drawSelectorOnTop" but for a simple layout

now the selector does not apply when the user press "state_pressed"

here is my code :

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="@drawable/cell_background_selector" >

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#282828"
        android:paddingBottom="5dp" >
..
......
........
</RelativeLayout>
</FrameLayout>

here is my selector code :

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

    <item android:drawable="@drawable/video_blank" android:state_pressed="true"/>
     <item android:drawable="@drawable/fav_show"/>
</selector>

both images exist , but the FrameLayout always apply the normal state drawable as a Foreground

like image 982
user4o01 Avatar asked Oct 21 '12 23:10

user4o01


People also ask

What is foreground attribute in Android?

The documentation states the android:foreground defines the drawable to draw over the content , it doesn't state anywhere that the content has to be a ViewGroup . And the tag is defined for the View class.

What's the purpose of FrameLayout?

Frame Layout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.

What is foreground gravity Android?

3. android:foregroundGravity. Defines the gravity to apply to the foreground drawable. The gravity defaults to fill. Possible values are top, bottom, left, right, center, center_vertical, center_horizontal etc.

What is the use of FrameLayout in Android?

Android Framelayout is a ViewGroup subclass that is used to specify the position of multiple views placed on top of each other to represent a single view screen. Generally, we can say FrameLayout simply blocks a particular area on the screen to display a single view.


1 Answers

Old question, but was the first hit on Google when I encountered a similar problem.

Do you have an OnClick listener set for the FrameLayout? If not, the pressed state will never be used.

like image 62
SpeedBurner Avatar answered Sep 19 '22 22:09

SpeedBurner