在点击或点击其边界外时,消除视图(RelativeLayout,LinearLayout或任何视图)?

时间:2013-05-17 05:05:00

标签: android relativelayout

有人知道如何在不使用我希望消失的视图下方的透明视图的情况下这样做吗?

1 个答案:

答案 0 :(得分:0)

假设你有这样的布局,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/parent"
android:layout_height="match_parent"
tools:context=".LoginActivity" >

<ImageView
    android:id="@+id/imageview"
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:src="@drawable/abs__progress_medium_holo"
    android:visibility="invisible" />
</RelativeLayout>

在你的代码添加中,

RelativeLayout rl=(RelativeLayout)findViewById(R.id.parent);

    ImageView img=(ImageView)findViewById(R.id.imageView);

    rl.setOnClickListener(new View.OnClickListener() {

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

            img.setVisibility(View.GONE);


        }
    });

或试试这个,

 public boolean onTouchEvent(MotionEvent event) {
 if(event.getAction() == MotionEvent.ACTION_OUTSIDE)
   { 
      imageview.setVisibility(View.GONE); 
   } 
       return true; 
}