2014-10-29 4 views
0

나는 서버로부터 얻은 비트 맵 배열을 표시하는 arrayadapter를 가지고있다. 최대 4 개의 비트 맵을 화면에 동시에 표시 할 수 있으며 일반적으로 "홀더"패턴을 사용하여 목록을 순환시킵니다. 비트 맵은 객체 내에 포함되어 있으며 그 속성 중 하나는 날짜입니다. 비트 맵 객체의 날짜가 X보다 큰 경우 목록의 특정 비트 맵 위에 레이어를 넣을 수 있기를 원합니다. "new "투명도 50 %.arrayadapter에서 framelayout 상단에 뷰를 쌓기

이렇게하려면 기존 비트 맵 레이아웃에 framelayout을 추가하고 이것에 addView를 수행하고 "새로운"레이어 (별도의 레이아웃 파일에 있음)를 추가하고 비트 맵에서 부울 플래그를 변경합니다. 어떤 시점에서 내가 "새로운"것으로 표시했다는 것을 보여주는 객체. 비트 맵이 오래되어서 과거의 어떤 시점에서 "새로운"것으로 표시 되었다면 플래그를 old로 변경하고 새 레이어를 제거합니다.

문제는 내가 목록을 뒤지고 "새 것"이어야하는 비트 맵을 발견 할 때 올바르게 표시되지만 목록을 백업하고 다시 백업하면 목록이 점진적으로 독이되어 결국 결국 비트 맵은 "새로운"것으로 표시됩니다. 또한 "새로운"레이어의 배경은 50 % 투명하게 시작되고 목록의 위아래로 약간 움직이면 모두 검정색으로 표시되어 "새로운"레이어를 목록에 계속 추가합니다. 모든 단일 비트 맵. "새로운"레이어

레이아웃 파일 (R.layout.new_over_layer) :

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/half_transparent" 
android:gravity="top|center_horizontal" 
> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="100dp" 
    android:src="@drawable/new_icon" 
    android:background="@color/transparent" 
    /> 

레이아웃 파일을 여기에 관련 코드가 - 조금 더 명확이 설명을 만들려면 모든 비트 맵

<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout 
android:id="@+id/newlistview_framelayout" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/white" 
android:foregroundGravity="top|center_horizontal" 
> 

<RelativeLayout 
android:layout_width="fill_parent" 
android:layout_height="180dp" 
android:layout_marginBottom="4dp" 
android:background="@color/white" > 



<ImageView 
    android:id="@+id/some_bitmap" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:layout_marginBottom="4dp" 
    android:contentDescription="@string/some_bitmap_desc" 
    android:scaleType="fitXY" 
    android:src="@color/black" /> 

</RelativeLayout> </FrameLayout> 

관련 코드 섹션에 대한 어댑터

public class myCustomAdapter extends ArrayAdapter<BitmapObject> 
{ 
public View getView(final int position, View convertView, ViewGroup parent) { 
    ViewHolder holder; 
    View currentView = convertView; 

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
    View newBitmapLayer = inflater.inflate(R.layout.new_over_layer,parent,false); 

    getCurrentTime(); 

    if (isBitmapNew(bitmapList.get(position))) { 

     if (!bitmapList.get(position).getNew()) { 
      bitmapList.get(position).setNew(true); 
      ((FrameLayout)  currentView.findViewById(R.id.newlistiview_framelayout)).addView(newBitmapLayer); 
     } 
    } else { 

     if (bitmapList.get(position).getNew()) { //check if marked new before and reset to old 
      bitmapList.get(position).setNew(false); 
      ((FrameLayout)  currentView.findViewById(R.id.newlistiview_framelayout)).removeView(newBitmapLayer); 
     } 
    } 

    if (null == currentView) { 

     currentView = inflater.inflate(R.layout.new_listiview_item, parent, false); 

     holder = new ViewHolder(); 
     holder.bitmapName = (TextView) currentView.findViewById(R.id.bitmap_name); 
     currentView.setTag(holder); 

    } else { 
     holder = (ViewHolder) currentView.getTag(); 
    } 

.... 
} 

그래서 .. 왜 나는 목록 중독 자체로 스크롤 할 때 아래, 그리고 제대로 기능하도록 어떻게 코드를 변경 할 만해야하는 모든 비트 맵에 "새로운"한 번 추가 새로운 것으로 표시 되나요?

답변

1

이 작업을 완전히 바꾸어서 해결했습니다. 목록에서 레이어를 추가 및 제거하는 대신 투명도가 "새"인 레이어를 framelayout의 영구 하위 레이어로 만들었습니다. 그런 다음 비트 맵이 새로울 때마다 "새로운"레이어에서 bringchildtofront를 사용하고 비트 맵이 새롭지 않을 때마다 비트 맵 레이어에 bringchildtofront를 사용했습니다.이 레이어는 100 %의 불투명도를 가지므로 "새로운"레이어를 숨 깁니다.

 if (isBitmapNew(bitmapList.get(position))) { 

     ((FrameLayout) currentView.findViewById(R.id.newlistiview_framelayout)).bringChildToFront(currentView.findViewById(R.id.bitmap_new)); 

    } else { 

     ((FrameLayout) currentView.findViewById(R.id.newlistiview_framelayout)).bringChildToFront(currentView.findViewById(R.id.bitmap_old)); 
    } 

레이어를 추가하거나 제거하지 않으므로 목록이 훨씬 빠르게 작동하고 중독 될 수 없습니다.