2011-04-16 13 views
7

मुझे निम्न लेआउट फ़ाइल मिली है, जिसमें पृष्ठभूमि के रूप में GridView और ImageView है।मैं पूरी स्क्रीन का उपयोग करने के लिए ग्रिड व्यू को कैसे मजबूर कर सकता हूं (प्रदर्शन आकार के बावजूद)?

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#FFFFFF"> 
    <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|right" 
      android:layout_marginRight="-70dp" 
      android:layout_marginBottom="-50dp" 
      android:src="@drawable/s_background"/> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"> 
     <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/gridview" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:columnWidth="90dp" 
        android:numColumns="auto_fit" 
        android:verticalSpacing="10dp" 
        android:horizontalSpacing="10dp" 
        android:stretchMode="columnWidth" 
        android:gravity="center"/> 
    </LinearLayout> 
</FrameLayout> 

और यह लेआउट मैं ग्रिड के प्रत्येक "सेल" में वास्तविक आइटम के लिए उपयोग करते हैं:

<?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"> 
    <TextView 
      android:id="@+id/cardInGrid" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:singleLine="true" 
      android:textSize="40sp" 
      android:textColor="#660099" 
      android:typeface="serif"/> 
</LinearLayout> 

मैं इस समय अपने डिवाइस पर निम्नलिखित दिखाई दे रही है:

enter image description here

क्या प्रत्येक आइटम को ग्रिडव्यू में बड़ा बनाने का कोई तरीका है, इसलिए यह स्क्रीन के आकार को फिट करता है और मेरे पास डिस्प्ले के नीचे अन-उपयोग की गई सफेद जगह नहीं है?

यह एक एमुलेटर पर ठीक काम करता है, लेकिन डिवाइस पर स्क्रीन रिज़ॉल्यूशन अधिक होता है, इसलिए नीचे सफेद स्थान प्राप्त होता है।

बहुत धन्यवाद

+0

दिलचस्प बात यह है कि अगर मैं 'एंड्रॉइड: minSdkVersion' को कुछ भी सेट करता हूं, जैसे 6/7/8 मुझे उपरोक्त व्यवहार मिलता है। जिस क्षण मैं इसे पूरी तरह से हटा देता हूं, ग्रिडव्यू अधिक स्क्रीन स्पेस भरता है। कोई विचार? – Jimmy

+0

एस्ले को ग्रिडव्यू के बारे में कोई समाधान मिला है? मुझे एक ही समस्या का सामना करना पड़ रहा है ... –

+0

@parag: क्या आप इस मुद्दे के बारे में मेरी मदद कर सकते हैं ........ –

उत्तर

3

स्वचालित रूप से नहीं।

विशेष रूप से, आपकी कोशिकाएं टेक्स्ट हैं। एंड्रॉइड यह अनुमान लगाने की स्थिति में बिल्कुल सही नहीं है कि आपके लक्ष्य को पूरा करने के लिए टेक्स्ट कितना बड़ा होना चाहिए, खासकर जब आप खाते में शब्द-लपेट लेते हैं।

GridView का बिंदु "प्रदर्शन के निचले भाग में गैर-उपयोग की गई सफेद जगह" है, यदि आपके पास स्क्रीन भरने के लिए पर्याप्त डेटा नहीं है, तो यह लचीला रूप से एकाधिक स्क्रीन आकारों को संभाल सकता है और स्क्रॉलिंग को समायोजित भी कर सकता है यदि अधिक डेटा है। यदि आप डैशबोर्ड पैटर्न के समान कुछ करने का लक्ष्य रखते हैं, तो DashboardLayout या उन पंक्तियों के साथ कुछ उपयोग करने पर विचार करें।

+1

डैशबोर्डलाइट गिटहब पर रीडायरेक्ट करता है, एंड्रॉइड नहीं! यह मेरे लिए एक महत्वपूर्ण विवरण है, कम से कम ... – Radu

0

क्या आपने android:layout_weight="1" को आजमाया है?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
    <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/gridview" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:columnWidth="90dp" 
       android:numColumns="auto_fit" 
       android:verticalSpacing="10dp" 
       android:horizontalSpacing="10dp" 
       android:stretchMode="columnWidth" 
       android:gravity="center" 
android:layout_weight="1"/> 
</LinearLayout> 

या

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
android:layout_weight="1"> 
    <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/gridview" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:columnWidth="90dp" 
       android:numColumns="auto_fit" 
       android:verticalSpacing="10dp" 
       android:horizontalSpacing="10dp" 
       android:stretchMode="columnWidth" 
       android:gravity="center" 
/> 
</LinearLayout> 

आशा है कि मदद करता है?

+0

मैंने उन लोगों की कोशिश की है, दुर्भाग्य से उनमें से कोई भी कोई प्रभाव नहीं प्रतीत होता है। :( – Jimmy

+0

हान: (हो सकता है कि यह ग्रिडव्यू के साथ संभव नहीं है जैसे कि एक मानक ग्रिडव्यू सिर्फ – wired00

16

यह अच्छी तरह से काम करेगा। ऊर्ध्वाधर रिक्ति के बारे में मत भूलना।

public class MyAdapter extends BaseAdapter { 
    public static int ROW_NUMBER = 5; 

    public MyAdapter (Context mContext, ArrayList<String> list) { 
     this.context = mContext; 
     lstDate = list; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
      convertView = LayoutInflater.from(context).inflate(R.layout.item, null); 
     } 
     // we need to decrease cell height to take into account verticalSpacing for GridView 
     int cellHeight = StrictMath.max(parent.getHeight()/ROW_NUMBER - parent.getContext().getResources().getDimensionPixelOffset(R.dimen.grid_spacing), 320); 
     AbsListView.LayoutParams param = new AbsListView.LayoutParams(
       ViewGroup.LayoutParams.MATCH_PARENT, 
       parent.getHeight()/ROW_NUMBER); 
     convertView.setLayoutParams(param); 

     return convertView; 
    } 
+1

से नीचे व्हाइटस्पेस के साथ आइटम नीचे दिखाने के लिए डिज़ाइन किया गया है, यह दृश्य नहीं होने से पहले एडाप्टर डेटा उपलब्ध होने पर काम नहीं कर सकता है। पहला माता-पिता के सामने भी ऊंचाई हो सकती है।साथ ही, आपको अपने एडाप्टर में 'ग्रिड व्यू' का संदर्भ प्राप्त करने की आवश्यकता नहीं है: 'पैरेंट' पैरामीटर में पहले से ही शामिल है। –

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

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