我的布局中有一个按钮和图像视图。当单击按钮时,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);}
}