2012-06-22 24 views
7

में दिखाई नहीं दे रहा है मैं कुछ ListView पर काम कर रहा हूं, मैं इसके तहत Button प्रदर्शित करना चाहता हूं, मैं निम्नलिखित कोड का उपयोग कर रहा हूं लेकिन यह काम नहीं कर रहा है।सूची दृश्य के तहत बटन एंड्रॉइड

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

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:cacheColorHint="#00000000" 
    android:drawSelectorOnTop="false" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

</LinearLayout> 

बटन दिखाई नहीं दे रहा है, मुझे नहीं पता क्यों: /। किसी भी मदद सहायक मदद मिलेगी।

+0

यह wrap_content की, उदाहरण के लिए '150dp' के बजाय एक निर्धारित चौड़ाई मूल्य दे रही है की कोशिश करो। – Mxyk

+0

मैंने कोशिश की और बटन क्षेत्र में सूचीबद्ध सूचीदृश्य। – EJK

उत्तर

9

सूची दृश्य पूरे पृष्ठ का समय लगता है। अपने कोड में तत्वों को वांछित वजन देने का प्रयास करें। वजन = "1" .......... भीतर: इस कोड का उपयोग,

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

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:cacheColorHint="#00000000" 
    android:drawSelectorOnTop="false" 
    android:layout_weight="5" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_weight="1" /> 

</LinearLayout> 
+1

एंड्रॉइड का उपयोग करने के लिए अच्छा: एंड्रॉइड के बजाय layout_weight: वजन। – Mornor

8

ऐसा इसलिए हो रहा है क्योंकि ListView ऊंचाई wrap_content पर सेट है, जो इसे बटन के लिए स्क्रीन पर कोई स्थान छोड़ने वाले सभी आइटम को समायोजित करने के लिए विस्तारित करता है। आप शेष अंतरिक्ष पर कब्जा करने के नीचे और फिर सूचीदृश्य साथ बटन की स्थापना रिश्तेदार लेआउट का उपयोग कर सकते हैं:

<?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" > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_alignParentBottom="true" /> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:cacheColorHint="#00000000" 
    android:drawSelectorOnTop="false" 
    android:layout_above="@id/button1" /> 

</RelativeLayout> 
+0

यह बटन हमेशा स्क्रीन के नीचे फ़्लोट करेगा। प्रभाव नहीं है जहां आप सूची को स्क्रॉल कर सकते हैं और बटन ढूंढ सकते हैं। –

+0

लेकिन यह नहीं है कि सेशन क्या पूछ रहा था। –

5

मैं इस लाइन .............. एंड्रॉयड जोड़ लिया है सूची नीचे

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

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:cacheColorHint="#00000000" 
    android:drawSelectorOnTop="false" 
    android:weight="1" 
/> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

</LinearLayout> 
+0

आपको अपने परिवर्तन लिखना चाहिए, हमें आपके और ओपी कोड – maskacovnik

+1

में भिन्नताएं मिलनी हैं मैंने इस लाइन को जोड़ा है .............. एंड्रॉइड: वजन = "1" ..... ..... सूची के भीतर – Cloy

+0

इस चीज़ ने मुझे भी मदद की ............... धन्यवाद – krishnamahadik

0

वजन जोड़ने या नीचे संरेखित करने से बटन हमेशा स्क्रीन के नीचे फ़्लोट कर देगा। और सूची नीचे जायेगी।

यदि सूची को स्क्रॉल करने के बाद बटन प्रदर्शित करना चाहते हैं, तो सूची दृश्य में एक पाद लेख के रूप में बटन जोड़ें।

1

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

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_shipping_address" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background_all" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.reallymake.android.pottery.ShippingAddressActivity"> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView9" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="13dp" 
    android:background="@drawable/button_shape" 
    android:text="@string/ok" 
     /> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/btn_add_new_address" 
    android:orientation="vertical"> 


    <ListView 
     android:id="@+id/lv_addresses" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/list" 
     android:layout_marginTop="14dp" 
     android:layout_weight="1" /> 

    <Button 
     android:id="@+id/btn2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/lv_addresses" 
     android:layout_marginTop="14dp" 
     android:background="@drawable/button_shape" 
     android:text="@string/proceed" /> 
</LinearLayout> 

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