如何将前景属性设置为其他非 FrameLayout 视图 [英] How to set foreground attribute to other non FrameLayout view

查看:37
本文介绍了如何将前景属性设置为其他非 FrameLayout 视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在不同于 FrameLayout 的视图中应用或模拟前景效果,如 LinearLayout 或 RelativeLayout

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>

我想要类似的东西:

<?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>

提前致谢!!

推荐答案

这个想法是用一个 FrameLayout 包围你的布局,并将选择器和 onClick 事件设置为这个布局.

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/

或者你可以扩展rhis FRelativeLayout https://gist.github.com/shakalaca/6199283

Or you can extend rhis FRelativeLayout https://gist.github.com/shakalaca/6199283

这篇关于如何将前景属性设置为其他非 FrameLayout 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆