2013-05-29 4 views
10

मैं निश्चित हेडर और पाद लेख के साथ ListView कैसे बना सकता हूं?एंड्रॉइड लिस्ट व्यू फिक्स्ड हेडर और पाद लेख

मैं नहीं चाहता कि हेडर/पाद लेख ListView में आइटम के साथ स्क्रॉल करना चाहता है।

यह संभव शीर्षलेख/पादलेख ListView तो शीर्षलेख/पादलेख न एक सीधे नीचे/ऊपर पृष्ठभूमि और शीर्षलेख/पादलेख दृश्य की पृष्ठभूमि के नीचे ListView आइटम स्क्रॉल करने की जरूरत है, लेकिन अभी भी उस पर चल रहा है कि है सूची का पहला तत्व दिखाएं?

उत्तर

14

मैं @blackbelt सुझाव और स्रोत छवि एक टाइल पृष्ठभूमि के साथ transparant होने के साथ एक छोटे से imageView का उपयोग करके इसे हल किया।

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

<ListView 
android:id="@+id/lv" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
    android:layout_above="@+id/tv_footer" 
android:layout_below="@+id/tv_header" /> 

<TextView 
android:id="@+id/tv_footer" 
android:layout_width="fill_parent" 
android:layout_height="40dp" 
android:layout_alignParentBottom="true" 
android:layout_centerHorizontal="true" 
android:background="@drawable/footer_bg" 
android:gravity="center" 
android:text="Footer" /> 

<TextView 
android:id="@+id/tv_header" 
android:layout_width="fill_parent" 
android:layout_height="40dp" 
android:layout_alignParentTop="true" 
android:layout_centerHorizontal="true" 
android:background="@drawable/header_bg" 
android:gravity="center" 
android:orientation="vertical" 
android:text="Header" /> 

<ImageView 
android:id="@+id/iconView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:layout_alignParentTop="true" 
android:src="@drawable/ic_launcher" /> 

<ImageView 
android:id="@+id/imageView2" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:layout_alignTop="@+id/lv" 
android:background="@drawable/header_bg2" 
android:src="@drawable/transparant_bg_tile" /> 

<ImageView 
android:id="@+id/imageView1" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_above="@+id/tv_footer" 
android:layout_alignParentRight="true" 
android:background="@drawable/footer_bg2" 
android:src="@drawable/transparant_bg_tile" /> 

</RelativeLayout> 

डिवाइस enter image description here

7

LinearLayout का उपयोग करें, ListView और ऊपर के पाद लेख पर अपना शीर्षलेख जोड़ें। ListView layout_weight="1"

+1

यह काम करता है और बिना किसी बदलाव के मेरे रैखिक लेआउट में सही फिट बैठता है। धन्यवाद – Veeru

1

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

11

http://developer.android.com/reference/android/widget/ListView.html#addHeaderView%28android.view.View%29 का उपयोग कर अपने स्वयं के कस्टम दृश्य बनाएँ। AddHeaderView (param) के लिए इसे जांचें।

http://developer.android.com/reference/android/widget/ListView.html#addFooterView%28android.view.View%29। AddFooterView (param) के लिए इसे जांचें।

@Android listview with header and footer buttons

आप शीर्ष लेख और पाद जोड़ने के लिए सूची के लिए addHeaderView और addFooterView उपयोग कर सकते हैं एक लेआउट inlfating द्वारा विधि usuage का उदाहरण।

आप @blackbelt के सुझाव के अनुसार कर सकते हैं। मैंने LinearLayout के बजाय एक सापेक्ष लेआउट का उपयोग किया है।

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

<ListView 
    android:id="@+id/lv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
     android:layout_above="@+id/textView1" 
    android:layout_below="@+id/tv1" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="fill_parent" 
    android:layout_height="40dp" 
    android:gravity="center" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentBottom="true" 
    android:text="Footer" /> 

<TextView 
    android:id="@+id/tv1" 
    android:layout_width="fill_parent" 
    android:layout_height="40dp" 
    android:gravity="center" 
    android:layout_alignParentTop="true" 
    android:orientation="vertical" 
    android:layout_centerHorizontal="true" 
    android:text="Header" /> 

</RelativeLayout> 

चित्रमय लेआउट तस्वीर गोली मार दी

enter image description here

+0

यह ठीक काम करता है। मैंने इस समाधान का उपयोग किया लेकिन शीर्षलेख/पाद लेख के ऊपर और ऊपर के आलू के प्रभाव के लिए एक टाइल पृष्ठभूमि के साथ एक ट्रांसपरेंट छवि दृश्य जोड़ा। – Goran

+0

@ गोरान pls एक बार टिक पर क्लिक करके जवाब चिह्नित करता है अगर यह मदद करता है। यह – Raghunandan

1

से स्क्रीनशॉट के रूप में नीचे

header.xml फ़ाइल

<RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <TextView  
      android:layout_width="match_parent" 
      android:layout_height="your custom height" // you may set default too 
      /> 

    </RelativeLayout> 

पाद लेख अपनी सूची दृश्य कोड के साथ अपने कस्टम शीर्ष लेख और पाद बनाने ।xml फ़ाइल

<RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </RelativeLayout> 

ऐड जहाँ आपके सूचीदृश्य

LayoutInflater inflaterHeader = getLayoutInflater(); 
    ViewGroup header = (ViewGroup) inflaterFooter.inflate(
        R.layout.header, list_view, false); 
    yourListView.addHeaderView(header); 

    LayoutInflater inflaterFooter = getLayoutInflater(); 
      ViewGroup footer = (ViewGroup) inflaterFooter.inflate(
        R.layout.footer, list_view, false); 
    yourListView.addFooterView(footer); 
+0

ग्रेट सॉल्यूशन पर आने वाले अन्य लोगों को आकर्षित करेगा। धन्यवाद। – confile

0

हम इस तरह से शीर्ष लेख और पाद सेट कर सकते हैं भी, मैं सूचीदृश्य ऊपर और हम डिब्बे एट पाद लेख के नीचे एक ही तरीके से हैडर लेआउट की स्थापना कर रहा हूँ सूचीदृश्य

<LinearLayout 
     android:id="@+id/ly_header" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:background="@color/app_theme_color" 
     android:orientation="horizontal"> 
     <include layout="@layout/header_icuc"/> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/lv_contacts" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/ly_header" 
     android:background="#F3F4F6" 
     android:divider="@drawable/contact_list_divider" 
     android:dividerHeight="2dp" 
     android:scrollbars="none" /> 
संबंधित मुद्दे