2011-12-01 11 views
6

人の通信履歴を格納するリストビューがあります。私は、編集テキストと送信ボタンを持つメッセージエディタとして機能するlistviewの中に1つのヘッダを持っています。 ユーザーが何かを入力して送信ボタンを押すと、メッセージは通信リストに追加され、エディタは空になります。ClassCastExceptionを与えるListViewのヘッダをアニメ化する

私が望むのは、ユーザーが送信ボタンを押したときに、エディタが非表示になり、Itemがリストビューに追加される必要があることです。その後、エディタは上から徐々に来て、下の項目を動かしていると感じるようになるはずです。

私はヘッダーに翻訳アニメーションを実装しましたが、それはアイテムを押し下げてスペースを作ってから、私が必要としないスペースを徐々に埋めることです。

私はthis questionで説明されている負のマージンのトリックを使用しましたが、それは私のためには機能しませんでした。ヘッダーのAbsListView.LayoutParam以外のレイアウトパラメータを使用することはできません。他のパラメータを設定しようとしましたが、アニメーション中にClassCastExceptionが返されます。例外を追跡し、ListView内に記述されたコードにより、clearRecycledState()メソッド内のAbsListView.LayoutParamsでこれらのパラメータをキャストしようとしています。

または、リストビューヘッダーに余白をサポートするレイアウトパラメータを適用する方法がありますか?

コード

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を使用してください。実際にはリストをスクロールしているだけですが、その効果はあなたが探しているものである可能性があります。

関連する問題