我是新來的android和嘗試構建一個android應用程序。Android圖像視圖顯示setVisibility不見了
我將兩個圖像視圖一起堆疊。我想要做的是當用戶點擊頂部圖像時,最下面的圖像出現。當用戶點擊底部圖像時,出現頂部圖像。
問題是我點擊頂部圖像後,底部圖像顯示了一秒,然後頂部圖像再次出現。
下面是代碼:
View view = inflater.inflate(R.layout.list_item, null);
ImageView top = (ImageView) view.findViewById(R.id.top);
top.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
View parent = (View)v.getParent();
ImageView top =
(ImageView)parent.findViewById(R.id.top);
top.setVisibility(View.GONE);
ImageView bottom =
(ImageView)parent.findViewById(R.id.bottom);
bottom.setVisibility(View.VISIBLE);
}
});
ImageView bottom = (ImageView) view.findViewById(R.id.bottom);
bottom.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
View parent = (View)v.getParent();
ImageView top =
(ImageView)parent.findViewById(R.id.top);
top.setVisibility(View.VISIBLE);
ImageView bottom =
(ImageView)parent.findViewById(R.id.bottom);
bottom.setVisibility(View.GONE);
}
});
這裏是佈局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentRight="true"
android:src="@drawable/stop" />
<ImageView
android:id="@+id/top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentRight="true"
android:src="@drawable/ok" />
</RelativeLayout>
首先這是什麼觀點!!! ImageView iv =(ImageView)view.findViewById(R.id.expand); –
我修改了我發佈的代碼。 ImageView iv是頂部的圖像。 – cui