【发布时间】:2014-07-20 16:21:18
【问题描述】:
例如,我想在该视图之外单击时隐藏该视图,
<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 我隐藏了 id="containerGrid" 的 RelativeLayout 视图,并在我单击 imageview 时使该 relativeLayout 视图可见。
所以我的要求是,当我在容器外部单击时,我想隐藏带有 id="containerGrid" 的容器 RelativeLayout。
我试图获取 framelayout 容器,当单击该容器时,检查是否显示了 relativelayout 容器,如果显示则使其视图消失。这是我尝试过的代码,
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);
}
}
});
我在上面的事情中哪里出错了。
实际上我在那个框架布局容器中也有地图,所以我期待当我点击地图时,relativelayout 容器应该去。
【问题讨论】:
-
在为
FrameLayout添加android:clickable="true"后尝试 -
我现在试过了,同样的问题,我点击地图,它没有隐藏。
标签: android google-maps android-view navigation-drawer layout-inflater