2012-05-21 19 views
7

को देखते हुए छोड़ देता है:एंड्रॉयड दिखाएँ/छिपाएँ टुकड़ा खाली स्थान

  1. स्क्रीन पर दो खड़ी रखा तत्वों (ViewPager और टुकड़ा) पहले वर्तमान में चयनित टुकड़ा (ViewFlipper) में
  2. कार्रवाई पाठ के बीच टॉगल आधारित और वेबव्यू-आधारित दृश्य शीर्ष खंड और छुपाएं/नीचे टुकड़े दिखाता है।

मनाया:

  1. नीचे टुकड़ा छिपाई जा रही है एक खाली जगह है, जहां नीचे टुकड़ा स्थित है छोड़ देता है।

मैंने कोशिश की दोनों सापेक्ष और LinearLayout लेकिन (ऊपर टुकड़ा weight=1 करने के लिए सेट के साथ) दोनों कोई प्रभाव के बाद नीचे टुकड़ा निकाल दिया जाता है मैं अभी भी पर खाली जगह है है नीचे

यहाँ शीर्ष स्तर लेआउट फ़ाइल है:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" android:layout_weight="1"/> 

<!-- This gets replaced with appropriate fragment at run time --> 
<LinearLayout 
    android:id="@+id/scrollFragmentPlaceholder" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="110dip" /> 
</LinearLayout> 

यहाँ कोड है कि टुकड़ा टॉगल है

Fragment scroll = getSupportFragmentManager().findFragmentById(R.id.scrollFragment); 
    if (scroll.isHidden() == isWebView) 
     return; // already handled, do nothing 
    FragmentTransaction tr = getSupportFragmentManager().beginTransaction(); 
    if (scroll != null && scroll.isAdded()) { 
     if (isWebView) { 
      tr.hide(scroll); 
     } else 
      tr.show(scroll); 
    } 
    tr.commit(); 

और यहाँ यह कैसा दिखता है: Bottom fragment is hidden

+0

आप विचार है कि बनी हुई है पर * .measure() कर की कोशिश की है ? – Codeman

+0

वास्तव में नहीं, लेकिन अगर मैं ऑर्डर को उलट देता हूं और टेक्स्ट वर्जन/छुपाएं दिखाता हूं तो यह ठीक से दिखाता है कि एंड्रॉइड के लिए – Bostone

+0

वेबव्यू खूनी अजीब है। क्या आप कुछ स्क्रीनशॉट शामिल कर सकते हैं ताकि मैं देख सकूं कि आप अधिक विशेष रूप से किस बारे में बात कर रहे हैं? यदि आप चाहते हैं कि वे आधा उपलब्ध स्थान लेना चाहते हैं तो आपको दोनों दृश्यों पर लेआउट Weight = 1 होना चाहिए। आपको यह सुनिश्चित करने की ज़रूरत है कि आप मूल दृश्य में अभिविन्यास = "लंबवत" भी निर्दिष्ट करें। – Codeman

उत्तर

16

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

public void onJobViewToggled(final boolean isWebView) { 
    if (isFinishing()) 
     return; 
    final Fragment scroll = getSupportFragmentManager().findFragmentById(R.id.scrollFragment); 
    if (scroll.isHidden() == isWebView) 
     return; // already handled, do nothing 
    final FragmentTransaction tr = getSupportFragmentManager().beginTransaction(); 
    if (scroll != null && scroll.isAdded()) { 
     if (isWebView) { 
      tr.hide(scroll); 
      // shell is the original placeholder 
      shell.setVisibility(View.GONE); 
     } else { 
      tr.show(scroll); 
      shell.setVisibility(View.VISIBLE); 
     } 
    } 
    tr.commit(); 
} 

ध्यान दें कि आप अभी भी दिखाने के लिए/चाहते हैं तो इस के लिए टुकड़ा छिपाने काम करने के लिए

+1

आप शैल कैसे प्राप्त कर रहे हैं? – Nick

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