2011-10-28 15 views
36

विशाल कोड डंप के लिए खेद है, लेकिन मैं वास्तव में खो गया हूं।एंड्रॉइड फ्रैगमेंट match_parent को ऊंचाई

MyActivity.java onCreate:

super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_singlepane_empty); 
mFragment = new PlacesFragment(); 
getSupportFragmentManager().beginTransaction() 
        .add(R.id.root_container, mFragment) 
        .commit(); 

PlacesFragment.java onCreateView:

mRootView = (ViewGroup) inflater.inflate(R.layout.list_content, null); 
return mRootView; 

नोट्स: mRootView एक ViewGroup वैश्विक, इसके बारे में कोई समस्या है, तो मेरा मानना ​​है कि। PlacesFragment एक सूचीफ्रेजमेंट है।

लेआउट:

activity_singlepane_empty.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/root_container" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#00f"> 
    <include layout="@layout/actionbar"/> 

    <!-- FRAGMENTS COME HERE! See match_parent above --> 

</LinearLayout> 

list_content.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/listContainer" 
     android:background="#990" 
     > 

     <ListView android:id="@android:id/list" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:drawSelectorOnTop="false" /> 

     <TextView android:id="@id/android:empty" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="@string/no_data_suggest_connection"/> 

</FrameLayout> 

समस्या: के रूप में आप देख सकते हैं, अपेक्षित व्यवहार खाली करने के लिए किया जाएगा स्क्रीन पर केंद्रित दिखाई देने के लिए उपरोक्त टेक्स्ट व्यू। ग्रहण में डिजाइन पूर्वावलोकन पर, यह ठीक है। केवल जब खंड के रूप में root_view में जोड़ा गया है तो फ्रेमलेआउट पूरी स्क्रीन भर नहीं पाएगा।

root_container नीला है, और फ्रेमलाउट पीला है, डीबग उद्देश्यों के लिए नीचे देखें। पीले रंग की फलक पूरी स्क्रीन भरना नहीं चाहिए?!?!?!

enter image description here

+0

यदि आप स्क्रॉलव्यू चेकआउट का उपयोग करते हैं तो यह: http://stackoverflow.com/questions/10211338/view-inside-scrollview-doesnt-take-all-place –

उत्तर

69

मैं एक ही समस्या थी और लगता है कि यह होता है जब आप अशक्त साथ टुकड़ा के onCreateView में लेआउट बढ़, जैसा आप यहां क्या किया:

mRootView = (ViewGroup) inflater.inflate(R.layout.list_content, null); 

इसके बजाय यदि आप ऐसा करना है:

mRootView = (ViewGroup) inflater.inflate(R.layout.list_content,container, false); 

कहाँ contai नज़र व्यू ग्रुप है। कम से कम, यह मेरे लिए समस्या हल हो गई।

+2

http://developer.android.com/reference/android/view/LayoutInflater.html जनरेटेड पदानुक्रम के माता-पिता होने के लिए वैकल्पिक दृश्य (यदि अटैचमेंट रूट सही है), या अन्यथा केवल एक ऑब्जेक्ट जो लेआउटपैम्स का एक सेट प्रदान करता है लौटा पदानुक्रम की जड़ के लिए मान (यदि अटैचमेंट ट्रॉट गलत है।) उत्तर स्वीकृत। धन्यवाद। – davidcesarino

+1

यह भी देखें http://stackoverflow.com/questions/5026926/making-sense-of-layoutinflater – Stevie

3

किसी कारण से FrameLayout एक्सएमएल से अपने लेआउट नहीं मिलता है।

मैं कोड में भी यह निर्धारित करने की आवश्यकता (टुकड़ा के onCreateView):

mRootView = (ViewGroup) inflater.inflate(R.layout.list_content, null); 
FrameLayout fl = (FrameLayout) mRootView.findViewById(R.id.listContainer); 
fl.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
return mRootView; 
+0

यह एक पुराना उत्तर है। तब से, मैंने स्वीकृति चिह्न को नॉर्मन के जवाब में बदल दिया। निस्संदेह यह उत्तर अधिक लचीलापन प्रदान करता है, लेकिन मुझे यह स्वीकार करने में प्रसन्नता हो रही है क्योंकि इस प्रश्न ने स्पष्ट रूप से उपयोग के लिए एक समाधान की आवश्यकता है। – davidcesarino

0

तरह से मैंने वह किया, एक्सएमएल कोड में एक पारदर्शी छवि बनाने टुकड़ा एक रिश्तेदार लेआउट बनाने के लिए और ImageView में layout_alignParentBottom="true", इस तरह से नीचे करने के लिए छवि छड़ें बनाने के लिए था और टुकड़ा माता-पिता को भरने बनाता

यहाँ

कोड:

temp_transparent.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:thickness="0dp" 
    android:shape="rectangle"> 
<gradient 
    android:startColor="#00000000" 
    android:endColor="#00000000" 
    android:type="linear" 
    android:angle="270"/> 

fragment_m y_invites।एक्सएमएल

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:id="@+id/my_invites_fragment" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#ffffff"> 


<ListView 
    android:id="@+id/list_invites" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:divider="@color/list_divider" 
    android:dividerHeight="1dp" 
    android:layout_alignParentTop="true" > 
</ListView> 

<ImageView 
    android:id="@+id/transparent_image" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_below="@id/list_invites" 
    android:src="@drawable/temp_transparent" /> 

4
<android.support.v4.widget.NestedScrollView 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:fillViewport="true" 
    > 

    <include layout="@layout/screen_main_fragment" /> 

</android.support.v4.widget.NestedScrollView> 

मैं layout_height = "wrap_content" बदलने के लिए करने के लिए "match_parent" यह काम करना था।

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