本文介绍了查看一去不复返了这一观点之外点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想躲认为,鉴于外点击时,例如,

I wanted to hide the view when clicking outside that view, for example,

<Framelayout android:id="@+id/container"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
  <fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

  <ImageView
    android:id="@+id/imgButtonToOpenGrid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right|bottom"
    android:src="@drawable/open_grid_img" 
    />

  <RelativeLayout 
    android:id="@+id/containerGrid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right|bottom"
    >

    <Button 
        android:id="@+id/button1grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/favourites"
        />

    <Button 
        android:id="@+id/button2grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/recent"
        android:layout_toRightOf="@+id/button1grid"
        />

    <Button 
        android:id="@+id/button3grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/gridview"
        android:layout_toRightOf="@+id/button2grid"
        />
  </RelativeLayout>
 </FrameLayout>

我在我的应用程序正在做的是在​​OnCreate我正在隐藏RelativeLayout的观点与ID =containerGrid,使该RelativeLayout的,当我点击查看ImageView的可见。

What I am doing in my app is oncreate i am hiding the RelativeLayout view with id="containerGrid" and making that relativeLayout view visible when I click on the imageview.

所以,我的要求是我想躲使用id =containerGrid当我点击容器外容器RelativeLayout的。

So my requirement is I wanted to hide the container RelativeLayout with id="containerGrid" when I click outside that container.

我试图让的FrameLayout容器,当该容器检查,如果显示的RelativeLayout容器或没有,如果显示遂作出其观点,转眼就点击。这里是code我尝试,

I tried to get the framelayout container and when clicked on that container checking if relativelayout container is shown or not , if shown then made its view gone. Here is the code i tried,

containerMap = (FrameLayout)findViewById(R.id.container);

containerMap.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub

        if(rltvContainer.isShown()){
            rltvContainer.setVisibility(View.GONE);

        }

    }
});

在哪里有我在上面的东西去错了。

Is there anywhere i am going wrong in above thing.

其实我刚才在的FrameLayout容器所以在这里,当我一个地图RelativeLayout的容器应该去点击我期待映射了。

Actually i have map too in that framelayout container so here i am expecting when i click on a map the relativelayout container should go.

推荐答案

添加其他 coverView 这是透明的地图片段的前

Add another coverView which is transparent in front of the map fragment

<Framelayout android:id="@+id/container"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
  <fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

  <View
    android:id="@+id/coverView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:background="#00000000"
    android:visibility="gone"
    />

  <ImageView
    android:id="@+id/imgButtonToOpenGrid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right|bottom"
    android:src="@drawable/open_grid_img" 
    />

  <RelativeLayout 
    android:id="@+id/containerGrid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right|bottom"
    >

    <Button 
        android:id="@+id/button1grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/favourites"
        />

    <Button 
        android:id="@+id/button2grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/recent"
        android:layout_toRightOf="@+id/button1grid"
        />

    <Button 
        android:id="@+id/button3grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/gridview"
        android:layout_toRightOf="@+id/button2grid"
        />
  </RelativeLayout>
 </FrameLayout>

在该 containerGrid 打开(这意味着它的'能见度 View.VISIBLE ,将 coverView 的能见度 View.VISIBLE

When the containerGrid is opened(which means its' visibility is View.VISIBLE, set the coverView's visibility to View.VISIBLE.

如果您想要关闭 containerGrid ,这是您要在外面 containerGrid 点击,你实际点击在 coverView ,设置 OnClickListener coverView

If you want to close containerGrid, which is that you want to click outside containerGrid, you actually click on the coverView, set OnClickListener to the coverView:

coverView.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub

        if(rltvContainer.isShown()){
            rltvContainer.setVisibility(View.GONE);
        }
        coverView.setVisibility(View.Gone);
    }
});

同时设置 coverView containerGrid View.GONE

这篇关于查看一去不复返了这一观点之外点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 15:12