我的布局中有一个按钮和imageview。当点击按钮时,imageview应该变得可见。即。算法是: 1)单击按钮 2)imageview变得可见 3)其他行动。 然而,它并不总是这样。有时在按钮上单击按钮保持黄色并且什么都不做,也没有抛出异常。当我点击屏幕上的任何位置时,它继续在步骤3,并再次取消选择按钮 这种奇怪行为可能是什么原因?
编辑:这是我的xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="fill_parent"
android:id="@+id/water_room_layout" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ViewFlipper android:id="@+id/water_room_flipper"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<include layout="@layout/water_room_wall1" android:id="@+id/first" />
<include layout="@layout/water_room_wall2" android:id="@+id/second" />
<include layout="@layout/water_room_wall3" android:id="@+id/third" />
<include layout="@layout/water_room_wall4" android:id="@+id/fourth" />
</ViewFlipper>
<com.example.room.CustomView
android:id="@+id/customView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
这是water_room_wall1.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/wall1Layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/wall1withkey"
tools:context=".FireRoomActivity"
>
<ImageView
android:id="@+id/zoomed_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/key_zoomed"
android:visibility="gone" />
<Button
android:id="@+id/key"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="150dp"
android:layout_marginTop="144dp"
android:onClick="zoomImage"
/>
</RelativeLayout>
这是我的活动:
int wall;
RelativeLayout parentLayout;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.water_room_view_flipper);
wall=1;
rl = (CustomView) findViewById(R.id.customView);
vf = (ViewFlipper) findViewById(R.id.water_room_flipper);
}
public void zoomImage(View view)
{
parentLayout = (RelativeLayout)findViewById(R.id.first);
if(view.getId()==R.id.key){
zoomedImage= (ImageView)parentLayout.findViewById(R.id.zoomed_image);
((BitmapDrawable)parentLayout.getBackground()).getBitmap().recycle();
//set Alpha
Drawable wall1withoutkey = getResources().getDrawable(R.drawable.wall1withoutkey);
wall1withoutkey.setAlpha(100);
parentLayout.setBackgroundDrawable(wall1withoutkey);
parentLayout.findViewById(R.id.key).setVisibility(View.INVISIBLE);
}
zoomedImage.setVisibility(View.VISIBLE);
zoomedImage.setClickable(true);
zoomedImage.setOnClickListener(this);}
}