안녕하세요.

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#ff0000" >

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center" >

        <ImageView
            android:id="@+id/a"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center" />

        <ImageView
            android:id="@+id/b"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center" />

       <ImageView
            android:id="@+id/c"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"

            android:visibility="gone" />

    </FrameLayout>

</LinearLayout>

 

위와 같은 구조를 가지고 그리드뷰를 구성하였습니다.

 

그리드뷰에서 아이템 하나를 터치하면

선택한 아이템의 a는 서서히 사라지고

나머지 아이템의 c는 서서히 나타나게 하였습니다.

 

제가 구현한 방법은 아이템을 터치를 하여도

화면이 스크롤 되지 않기 때문에 notifyDataSetChanged();를 호출 하여도 

getView()에서 아래 부분에서 else부분이 실행이 됩니다.

 

if (convertView == null){

}else{

  <<<<<<<<<<<<<<<<<<<<< 이부분이 실행됨

}

 

else  부분에 아래와 같이 구현을 하였습니다.(터치한 아이템 번호 : animValue)

if (animValue == index){
     Animation animation = new AlphaAnimation(1, 0);
     animation.setDuration(1000);
     holder.a.setVisibility(View.GONE);
     holder.a.startAnimation(animation);
    }else{
     Animation animation = new AlphaAnimation(0, 1);
     animation.setDuration(1000);
     holder.c.setVisibility(View.VISIBLE);
     holder.c.startAnimation(animation);
    }

위 내용은 정상적으로 동작을 하였습니다.

 

다시 원복을 할때는 아래와 같이 구현을 하였는데 여기서 문제가 발생하였습니다.

if (animValue == index){
     Animation animation = new AlphaAnimation(0, 1);
     animation.setDuration(1000);
     holder.a.setVisibility(View.VISIBLE);
     holder.a.startAnimation(animation);
    }else{
     Animation animation = new AlphaAnimation(1, 0);
     animation.setDuration(1000);
     holder.c.setVisibility(View.GONE);
     holder.c.startAnimation(animation);
    }

 

선택안된 아이템들은 정상적으로 c가 서서히 사라졌습니다.

그런데 선택된 아이템의 a는 서서히 나타났지만 선택된 아니템에서 c가 보여집니다.

 

이해하기 쉽게 자세히 적는다고 적었는데 설명이 잘되었나 모르겠습니다.

조언 부탁드립니다.

 

 

 

profile

give & take