I would like to know how to apply or emulate foreground effect in a view different from FrameLayout, as LinearLayout or RelativeLayout
This is what I have now:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/row_background"
android:foreground="@drawable/foreground_row">
...
</FrameLayout>
And I want something like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/row_background"
app:foreground="@drawable/foreground_row">
...
</RelativeLayout>
Thanks in advance!!
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.
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.
Foreground colors(colors which are before background colours) are the colours you see on the screen before the background colours.
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.
The idea is to surround your layout with a FrameLayout, and set the selector and the onClick event to this layout.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/selectableItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foreground="@drawable/foreground_row"
>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/row_background">
...
</RelativeLayout>
</FrameLayout>
You can find a full explanation at my blog:
http://antonioleiva.com/unveiling-bandhook-foreground-any-layout/
Or you can extend rhis FRelativeLayout
https://gist.github.com/shakalaca/6199283
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With