Android 如何使碎片变灰

Android 如何使碎片变灰,android,user-interface,interface,android-viewpager,fragment,Android,User Interface,Interface,Android Viewpager,Fragment,我的应用程序有一个带有以下片段的viewpager 1登录2测量3查看数据 用户登录并滑动到测量片段后,我的应用程序将自动测量一些参数 因为viewpager可以滑动。如果用户希望在不登录的情况下进行测量,则可以灰显/禁用片段 谢谢 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" androi

我的应用程序有一个带有以下片段的viewpager

1登录2测量3查看数据

用户登录并滑动到测量片段后,我的应用程序将自动测量一些参数

因为viewpager可以滑动。如果用户希望在不登录的情况下进行测量,则可以灰显/禁用片段

谢谢

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

    <ImageButton
        android:id="@+id/qt_deleteButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/qt_testtype"
        android:layout_marginLeft="28dp"
        android:layout_marginTop="18dp"
        android:layout_toRightOf="@+id/qt_saveButton"
        android:background="@drawable/border_button"
        android:src="@drawable/delete" />

    <ImageButton
        android:id="@+id/qt_saveButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/qt_deleteButton"
        android:layout_toRightOf="@+id/maintxt_measure"
        android:background="@drawable/border_button"
        android:src="@drawable/save" />

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/main_unknown" />

    </FrameLayout>

</RelativeLayout>

我已经将我的布局文件编辑到上面,但是下面的图层仍然可以单击。有什么我错过的吗


谢谢

对不起,不,这可能是它的样子:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- You may change this to your relative layout, just make sure it is fill_parent -->
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center">

        <!-- Everything related to your main activity goes here -->

    </LinearLayout>

    <LinearLayout
        android:id="@+id/faderLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center">

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#E0000000"
            android:onClick="faderClicked" />

    </LinearLayout>

</FrameLayout>


因此,在您的活动中,您将有一个功能
public void faderClicked(View v)
,其中它什么也不做,您可以通过更改faderLayout的可见性来控制视图。

从逻辑上讲,在测量和视图数据的布局上,您可以有一个包含所有内容的两层框架布局,顶部的一层是覆盖整个屏幕的灰色imageview,因此如果用户未登录,将显示此imageview,如果用户已登录,则将其可见性设置为gone。有了这个imageview,其他视图元素将不会收到任何感人的事件。嗨,WaiChun,根据你的建议,我已经更新了我的xml文件。但是,下面的按钮仍然可以单击。谢谢在你的imageview上这么做,实现一个onClickListner,它将调用一个完全不做任何事情的函数,然后它将阻止底层被访问。你可以参考下面我的答案。没有问题,很高兴我帮助了你。