2011-01-13 3 views
6

मैं ऊपर और नीचे क्षैतिज लीनियरलाउट्स के साथ एक लेआउट बनाना चाहता हूं, एक सूची दृश्य मध्य में भरें।लेआउट समस्या: ऊपर और नीचे कुछ कैसे रखें?

मैं main.xml को कैसे परिभाषित कर सकता हूं।

मैंने शीर्ष पर क्षैतिज लीनियरलाइट के साथ एक लेआउट बनाने की कोशिश की, नीचे टेक्स्टव्यू, एक सूची दृश्य मध्य में भरें; ठीक है। लेकिन जब मैंने नीचे टेक्स्टव्यू को रैखिकलायआउट में संशोधित किया, तो नीचे रैखिक लयआउट गायब हो गया।

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 
     <TextView 
      android:textSize="12px" 
      android:text="something here" 
      android:layout_width="50px" 
      android:layout_height="wrap_content" 
      /> 
     <TextView 
      android:textSize="12px" 
      android:text="something here" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="bottom" 
     > 
     <ListView 
      android:id="@+id/listbody" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      > 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12px" 
       android:text="50%" 
       /> 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12px" 
       android:text="50%" 
       /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

कोई भी सलाह दे सकता है? कृपया मदद करें।

उत्तर

11

एक RelativeLayout में पूरे सेट युक्त कोशिश:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/top_linear_layout_id" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" > 
    </LinearLayout> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/bottom_linear_layout_id" 
     android:layout_below="@id/top_linear_layout_id" /> 

    <LinearLayout 
     android:id="@+id/bottom_linear_layout_id" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 
    </LinearLayout> 
</RelativeLayout> 

आकार सामान के साथ संपादित।

+0

अब लिनियरलाइट सूचीव्यू के साथ ओवरलैप हो गया है! मुझे लगता है कि यह नीचे लिनियरलाउट की परिभाषा में कुछ गलत होना चाहिए। – chow

+0

विशेष रूप से नहीं। ListView के लिए, जोड़ें: \t एंड्रॉयड: layout_height = "wrap_content" \t एंड्रॉयड: layout_width = "fill_parent" \t एंड्रॉयड: layout_below = "@ आईडी/top_linear_layout_id" \t एंड्रॉयड: layout_above = "@ + id/bottom_linear_layout_id" रैखिक लेआउट के लिए संबंधित आईडी के साथ। – Estel

0

समस्या हो सकता है कि आप उन दोनों को सामग्री उनमें शामिल आकार के सापेक्ष परिभाषित कर रहे हैं, लेकिन अगर दोनों के संयुक्त सामग्री स्क्रीन से बड़ा है तो उनमें से एक, एक दूसरे को ओवरलैप करना होगा आप एक रैखिक लेआउट

3

में एक पूर्ण माप का उपयोग करके layout_height को परिभाषित करना बेहतर होगा, जो आप ढूंढ रहे हैं। एस्टेल का रिलेटिव लयआउट के साथ सही रास्ते पर है (हालांकि इसे लाइनरलाइट के साथ किया जा सकता है, मुझे लगता है कि रिलेवेटलाइट दृष्टिकोण क्लीनर है, हालांकि) लेकिन लेआउट ऑर्डर से बाहर है, एस्टेल की टिप्पणी की जांच करें जो मुझे गलत साबित करता है। :) आपको सबसे पहले अपना हेडर परिभाषित करना चाहिए, इसे शीर्ष पर संरेखित करना चाहिए; अगला, अपने पाद लेख को परिभाषित करें, और इसे नीचे संरेखित करें; अंत में, अपने ListView घोषित यह fill_parent की ऊंचाई देते हैं, और यह सेट पाद लेख के ऊपर और नीचे हैडर लेआउट करने के लिए: आपकी सलाह और RelativeLayout की दिशा के लिए सभी

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:alignParentTop="true" 
     > 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:alignParentBottom="true" 
     > 
    </LinearLayout> 

    <ListView 
     android:id="@+id/listview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/footer" 
     android:layout_below="@id/header" 
     /> 
</RelativeLayout> 
+0

ब्याज से, इस मामले में आदेश कितना महत्वपूर्ण है? जबकि हम स्पष्ट रूप से यह सुनिश्चित कर रहे हैं कि किसी भी विजेट की स्थिति में कोई ओवरलैप नहीं है, क्या ड्राइंग ऑर्डर तेजी से अनावश्यक नहीं हो रहा है? – Estel

+0

यहां पढ़ना: http://developer.android.com/guide/topics/ui/index.html#ViewHierarchy यह बताता है कि लेआउट को क्रम में पार्स किया गया है। इसलिए यदि फ़ूटर व्यू को फ़ूटर लेआउट से पहले घोषित किया गया है, तो यह स्क्रीन के निचले हिस्से में, शीर्ष स्थान से नीचे की जगह लेता है। फिर, पाद लेख सूची दृश्य के शीर्ष पर खींचा जाएगा, क्योंकि सूची दृश्य को उस समय पाद लेख से अवगत नहीं है जब इसे पार्स किया गया हो। मैं कहना चाहता हूं कि मैंने एंड्रॉइड 2 के रूप में पढ़ा है।2, ऑर्डर अब मायने रखता है (लेकिन फिर भी यदि आप पूर्व संस्करणों को लक्षित कर रहे हैं) लेकिन मुझे अब एक निश्चित संदर्भ नहीं मिल रहा है। – kcoppock

+0

एक चीज़ जो मैंने पाया http://developer.android.com/resources/articles/ui-1.6.html जो प्रासंगिक हो सकता है कि 1.6 उन संसाधनों के आगे संदर्भों को संदर्भित करता है जिन्हें पेड़ के नीचे घोषित किया जाता है। क्या आप इसका जिक्र कर रहे हैं? – Estel

0

धन्यवाद। मैं इसे अभी ठीक कर सकता हूं। layout_alignParentTop = "true" और एंड्रॉयड:

मैं ListView से पहले पाद लेख LinearLayout परिभाषित करने के लिए, और एंड्रॉयड के रूप में ListView परिभाषित है layout_above = "@ आईडी/पाद लेख"

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
    > 
     <TextView 
      android:textSize="12px" 
      android:text="something here" 
      android:layout_width="50px" 
      android:layout_height="wrap_content" 
      /> 
     <TextView 
      android:textSize="12px" 
      android:text="something here" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
     /> 
    </LinearLayout> 
    <RelativeLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    > 
     <LinearLayout 
      android:id="@+id/footer" 
      android:orientation="horizontal" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:layout_alignParentBottom="true" 
     > 

      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12px" 
       android:text="50%" 
       /> 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12px" 
       android:text="50%" 
      /> 

     </LinearLayout> 
     <ListView 
      android:id="@+id/tablebody" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_above="@id/footer" 
     /> 
    </RelativeLayout> 
</LinearLayout> 
0

यह निश्चित रूप से आपकी समस्या का समाधान होगा :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <TextView 
       android:textSize="12sp" 
       android:text="something here" 
       android:layout_width="50dp" 
       android:layout_height="wrap_content"/> 
      <TextView 
       android:textSize="12sp" 
       android:text="something here" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"/> 
     </LinearLayout> 
    </HorizontalScrollView> 
    <ListView 
     android:id="@+id/listbody" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 
    <HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent"> 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12sp" 
       android:text="50%"/> 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12sp" 
       android:text="50%"/> 
     </LinearLayout> 
    </HorizontalScrollView> 
</LinearLayout>