2011-12-01 4 views
6

나는 사람의 통신 기록을 저장하는 listview가있다. 하나의 헤더가 편집 텍스트와 보내기 버튼이있는 메시지 편집기의 역할을하는 listview 안에 있습니다. 사용자가 무언가를 입력하고 보내기 버튼을 누르면 메시지가 통신 목록에 추가되고 편집기가 비게됩니다.ClassCastException을주는 ListView의 헤더 애니메이션

내가 원하는 것은 사용자가 보내기 버튼을 누르면 편집자가 보이지 않게되고 항목이 목록보기에 추가되어야합니다. 그 후 편집기는 점차적으로 상단에서부터 아래 항목을 이동한다는 느낌을 주어야합니다.

헤더에 번역 애니메이션을 구현했지만 아이템을 아래로 밀면 공간이 생기고 점차 공간을 채 웁니다.

this question에 설명되어있는 음수 마술을 사용했지만 나에게 도움이되지 못했습니다. 머리말에 대해 AbsListView.LayoutParam과 다른 레이아웃 매개 변수를 사용할 수 없기 때문입니다. 다른 매개 변수를 설정하려고했지만 animating하는 동안 ClassCastException이 발생합니다. 예외를 추적하고 ListView 내부에 작성된 코드로 인해 clearRecycledState() 메서드 내에서 AbsListView.LayoutParams를 사용하여이 매개 변수를 캐스팅하려고합니다.

또는 listview-header에 여백을 지원하는 레이아웃 매개 변수를 적용하는 방법이 있습니까?

public class PageListView extends ListView { 
    private Application app; 
    private CommListAdapter listAdapter; 
    private MessageEditorHeader messageEditorHeader; 
    private MessageItemLongClick mInterface; 
    private Handler handler; 

public ProfilePageListView(Application app, MessageItemLongClick mInterface) { 
    super(app); 
    this.app = app; 
    this.mInterface = mInterface; 
    this.handler = new Handler(); 
    setupView(); 
} 

public void applyData(ProfileData data){ 

    listAdapter.applyData(data.getUser()); 
    // some other business logic   
} 

private void setupView() { 

    messageEditorHeader = new MessageEditorHeader(app); 
    addHeaderView(messageEditorHeader); 

    listAdapter = new CommListAdapter(app, mInterface); 
    setAdapter(listAdapter); 
    setDivider(null); 
    setScrollingCacheEnabled(false); 

    tAnimation = new TranslateAnimation(0.0f, 0.0f, -90.0f, 0.0f); 
    tAnimation.setZAdjustment(-1); 
    tAnimation.setDuration(1500); 
} 

// this gets called whenever the communication gets added to the listview. 
public void onNewCommunication(Communication lc) { 
    listAdapter.onNewCommunication(); 

    if(lc != null && lc.isOutgoing() && !lc.getType().isCall()){    
     getMessageEditor().startNewMessage(); 
     messageEditorHeader.setVisibility(VISIBLE); // this is overriden method here I m toggling the height 1px and WRAP_CONTENT 
     messageEditorHeader.startAnimation(tAnimation); 
    } 
} 

// few more methods are there. 
} 

는 heres는 메시지 편집기의 코드가

public class MessageEditorHeader extends RelativeLayout { 
private MessageEditor msgEditor; 

public MessageEditorHeader(AppteraApplication context) { 
    super(context); 
    msgEditor = new MessageEditor(context); // Its a relative layout containing edit text and the send button 
    addView(msgEditor); 
} 

public MessageEditor getMsgEditor() { 
    return msgEditor; 
} 

public void setProgress(int progress){ 
    msgEditor.setProgress(progress); 
} 

@Override 
public void setVisibility(int visibility) { 
    this.visibility = visibility; 
    if (visibility == View.VISIBLE) { 
     ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.FILL_PARENT, ListView.LayoutParams.WRAP_CONTENT); 
     setLayoutParams(params); 
    } 
    else { 
     ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.FILL_PARENT, 1); 
     setLayoutParams(params); 
    } 
} 
} 
+0

번역 애니메이션 파일을 게시하여 작동 방식을 생각할 수 있습니까? – DallaRosa

+0

질문을 편집했습니다. 코드를 살펴볼 수 있습니다. 내가 여기서하고있는 간단한 번역 애니메이션입니다. – wasaig

+0

코드에서 listView.addHeaderView (headerlayout)를 사용하고 있습니까? 그렇다면 머리글 설정 표시에 문제가없는 – bindal

답변

1

는 대신 다른 접근 방식에 대해 생각 해본 적이 코드? 어쩌면 목록 상단에 편집기보기를 놓고 화면 바깥쪽에 넣고 smoothScrollToPosition을 사용하여 전환 할 수 있습니다. 실제로 목록을 스크롤하는 것만으로 효과를 얻을 수 있습니다. .