如何调暗自定义布局的背景?

时间:2016-07-26 08:36:30

标签: java android

我创建了一个自定义布局,扩展了viewgroup,以便在1:18实现类似于此视频中的滑动菜单:https://www.youtube.com/watch?v=YeR7McJIltk

然而,当菜单滑入时,我不知道该怎么办会使背景内容变暗。

2 个答案:

答案 0 :(得分:2)

你可以这样做:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1">
        //your views are here

    </LinearLayout>

    <View
        android:id="@+id/dim"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#cc000000" />

</RelativeLayout>

仅在菜单打开时显示dim FrameLayout,在关闭菜单时隐身

答案 1 :(得分:0)

给出这样的背景。 android:background =“#8000”