Android Studio - 按钮顶部的相对布局具有透明背景

时间:2016-12-27 11:14:55

标签: android android-layout relativelayout

我正在尝试在包含RelativeLayout的另一个的顶部创建buttons,以便隐藏以下内容。

我已将黑色背景设置为顶部RelativeLayout但是,布局直到透明,显示下面的对象。此外,顶部相对布局后面的buttons仍然可以点击。

我的问题是如何使用RelativeLayout隐藏另一个包含对象的内容?顶部相对布局应该 NOT 透明,而下面的buttons不能可点击。

enter image description here

1 个答案:

答案 0 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:visibility="gone"
        android:id="@+id/buttons"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- Your buttons go here -->

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/prompt"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- your prompt -->

    </RelativeLayout>
</FrameLayout>

当你完成了你的提示相对布局时,那么从你的活动中说出这样的话:

View prompt = findeViewById(R.id.prompt);
prompt.setVisibility(View.GONE);

然后可见您的按钮布局

View buttonLayout = findeViewById(R.id.buttons);
buttonLayout.setVisibility(View.VISIBLE);