我希望在点击视图外部时隐藏视图,例如:
<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"的container RelativeLayout。
我尝试获取frameLayout容器,当点击容器时检查relativelayout容器是否显示,如果显示则将其视图设置为gone。以下是我尝试使用的代码:
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);
}
}
});
以上内容是否有任何错误?
实际上,我在框架布局容器中也有地图,所以我期望当我点击地图时,相对布局容器应该消失。
FrameLayout
و·»هٹandroid:clickable="true"
هگژé‡چ试م€‚ - ρяσѕρєя K