2011-12-01 8 views
6

दे रहे एक सूची दृश्य के एनिमेटिंग हेडर मेरे पास सूचीदृश्य है जो किसी व्यक्ति के संचार इतिहास को संग्रहीत करता है। मेरे पास एक सूचीदृश्य के अंदर एक हेडर है जो एक संपादन संपादक के साथ एक संदेश संपादक के रूप में कार्य करता है और एक भेजें बटन। जब कोई उपयोगकर्ता कुछ टाइप करता है और भेजें बटन दबाता है तो संदेश संचार सूची में जोड़ता है और संपादक खाली हो जाता है।क्लासकास्टएक्सप्शन

जब मैं चाहता हूं कि उपयोगकर्ता भेजें बटन दबाए, तो संपादक अदृश्य हो जाना चाहिए और आइटम को सूचीदृश्य में जोड़ा जाना चाहिए। उसके बाद संपादक को शीर्ष से धीरे-धीरे आना चाहिए जिससे यह महसूस हो रहा है कि यह नीचे दिए गए आइटम को ले जा रहा है।

मैंने हेडर पर एक अनुवाद एनीमेशन लागू किया है, लेकिन यह क्या करता है यह आइटम को नीचे दबाकर इसके लिए जगह बनाता है और फिर धीरे-धीरे उस स्थान को भर देता है जिसे मैं नहीं चाहता।

मैंने नकारात्मक मार्जिन चाल का उपयोग किया जो this question में समझाया गया है लेकिन यह मेरे लिए काम नहीं करता है। चूंकि हम हेडर्स के लिए AbsListView.LayoutParam अन्य लेआउट पैराम का उपयोग नहीं कर सकते हैं। मैंने अन्य पैरा सेट करने की कोशिश की लेकिन एनिमेटिंग करते समय यह मुझे क्लासकास्ट अपवाद देता है। मैंने अपवाद को ट्रैक किया और इसकी सूची लिस्ट व्यू के अंदर लिखे गए कोड के कारण वे इन पैराम्स को AbsListView.LayoutParams के साथ clearRecycledState() विधि के अंदर डालने की कोशिश कर रहे हैं।

या क्या लेआउट पैराम लागू करने का कोई तरीका है जो सूचीदृश्य-शीर्ष पर मार्जिन का समर्थन करता है।

कोड

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. 
} 

यहाँ संदेश संपादक का कोड

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 का उपयोग संक्रमण में करने के लिए करें। इसलिए वास्तविकता में आप केवल सूची को स्क्रॉल कर रहे हैं, लेकिन प्रभाव वह हो सकता है जिसे आप ढूंढ रहे हैं ।

संबंधित मुद्दे