禁用整个视图树

时间:2013-12-12 13:39:20

标签: android relativelayout android-view android-xml

我正在尝试在布局中显示另一个视图的视图,同时禁用后面的视图......

以下是一些屏幕截图,可以更好地理解我的要求:

Here is the first view

and the semitransparent view that goes over the top.

问题是我仍然可以点击后视图中的编辑文本字段。

这是我的XML代码:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/login_parent_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_body"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/kitu_logo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_gravity="center"
        android:padding="@dimen/login_logo_padding"
        android:src="@drawable/login_logo" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical">

        <ro.gebs.kitu.ui.custom.views.CustomFontEditText
            android:id="@+id/email_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/default_margin"
            android:layout_marginRight="@dimen/default_margin"
            android:layout_marginTop="@dimen/default_margin"
            android:background="@drawable/white_shape_border"
            android:hint="@string/email_hint"
            android:inputType="textEmailAddress"
            android:padding="@dimen/edit_text_padding" />

        <ro.gebs.kitu.ui.custom.views.CustomFontEditText
            android:id="@+id/password_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/default_margin"
            android:layout_marginLeft="@dimen/default_margin"
            android:layout_marginRight="@dimen/default_margin"
            android:background="@drawable/white_shape_no_top_border"
            android:hint="@string/password_hint"
            android:inputType="textPassword"
            android:padding="@dimen/edit_text_padding" />

        <ro.gebs.kitu.ui.custom.views.CustomFontButton
            android:id="@+id/login_btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/default_margin"
            android:layout_marginLeft="@dimen/default_margin"
            android:layout_marginRight="@dimen/default_margin"
            android:background="@drawable/custom_button"
            android:gravity="center"
            android:padding="@dimen/default_padding"
            android:text="@string/login"
            android:textColor="@android:color/white"
            android:textSize="20sp" />

        <ro.gebs.kitu.ui.custom.views.CustomFontTextView
            android:id="@+id/forgot_pass"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/default_margin"
            android:layout_marginLeft="@dimen/default_margin"
            android:layout_marginRight="@dimen/default_margin"
            android:gravity="center"
            android:text="@string/forgot_password"
            android:textColor="@color/purple_white_selector"
            android:textSize="17sp" />
    </LinearLayout>


    <ro.gebs.kitu.ui.custom.views.CustomFontButton
        android:id="@+id/register_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="@dimen/default_margin"
        android:layout_marginLeft="@dimen/default_margin"
        android:layout_marginRight="@dimen/default_margin"
        android:background="@drawable/custom_register_btn"
        android:gravity="center"
        android:padding="@dimen/default_padding"
        android:text="@string/register"
        android:textColor="@color/register_text_color"
        android:textSize="20sp" />

    <RelativeLayout
        android:id="@+id/loading_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/loading_backgroud"
        android:visibility="gone">

        <ImageView
            android:id="@+id/yellow_wheel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"

            android:src="@drawable/loading_yellow" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/incorrect_email_password_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/loading_backgroud"
        android:visibility="gone">

        <ro.gebs.kitu.ui.custom.views.CustomFontTextView
            android:id="@+id/popup_message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginLeft="@dimen/default_margin"
            android:layout_marginRight="@dimen/default_margin"
            android:layout_marginBottom="10dp"
            android:gravity="center"
            android:text="@string/noInternetConnection"
            android:textColor="#FFFF00"
            android:textSize="20sp" />

        <ro.gebs.kitu.ui.custom.views.CustomFontButton
            android:id="@+id/dismiss_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/popup_message"
            android:layout_centerInParent="true"
            android:layout_marginTop="20dp"
            android:background="@drawable/custom_dismiss_btn"
            android:gravity="center"
            android:paddingBottom="@dimen/default_padding"
            android:paddingLeft="30dp"
            android:paddingRight="30dp"
            android:paddingTop="@dimen/default_padding"
            android:text="@string/ok"
            android:textColor="@android:color/white"
            android:textSize="20sp" />

    </RelativeLayout>
</RelativeLayout>

在这里我尝试禁用后视图:

parentLayout.setEnabled(false);

这里初始化parentLayout

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.login_fragment, container, false);
        parentLayout = (RelativeLayout) view;
        initView(view);
        return view;
    }

1 个答案:

答案 0 :(得分:1)

您不需要使用view.setEnabled(false)。您可以将onTouchListener设置为上层封面,并且在onTouch方法的回调函数中,始终返回true。

在这种情况下,您的触摸事件不会“回退”到后面的视图。

相关问题