2011-02-25 14 views
8

मेरी लेआउट में मैं केवल आठ कोशिकाओं की है।
मैं सेल चाहते सभी जगह स्क्रीन पर उपलब्ध विभाजित करते हैं। क्या यह संभव है?मैं स्क्रीन ऊंचाई के आधार पर ग्रिड व्यू सेल की ऊंचाई कैसे सेट कर सकता हूं?

यह मेरी gridview लेआउट है:

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/dataGrid" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10px" 
    android:verticalSpacing="10px" 
    android:horizontalSpacing="10px" 
    android:numColumns="2" 
    android:gravity="fill" /> 

और इस मद लेआउट है:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="6dip" > 
    <TableRow 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:textColor="#E00000" 
      android:textStyle="bold" 
      android:gravity="left" 
      android:textSize="16dip"/>  
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:textColor="#000000" 
      android:textStyle="normal" 
      android:gravity="right" 
      android:textSize="12dip"/> 
    </LinearLayout> 
    </TableRow> 
</LinearLayout> 

उत्तर

0

पहले, PX के बजाय पी एस का प्रयोग करें। इससे इसे विभिन्न डीपीआई उपकरणों में स्केल करने की अनुमति मिलनी चाहिए।

दूसरा, प्रत्येक सेल को आकार देने के लिए, आप एक तालिका डाल सकते हैं जिसमें प्रत्येक सेल में एक स्पष्ट छवि है। पीएस (पीएक्स नहीं) के साथ छवि का आकार सेट करें। टेबल व्यू आपको प्रत्येक सेल में लेआउट ऑजेक्ट को ले जाने की अनुमति दे सकता है और स्पष्ट ग्राफिक को सभी कोशिकाओं को एक ही आकार में रखना चाहिए।

मैं किसी भी पैडिंग को भी हटा दूंगा।

हमें बताएं।

+0

मुझे क्षमा करें लेकिन मैं लगभग तीन दिनों के लिए इंटरनेट कनेक्शन से बाहर हूं ... वैसे भी मैं चाहता हूं कि ग्रिडव्यू किसी भी एंड्रॉइड डिवाइस के आधार पर स्क्रीन पर सभी जगहों को विभाजित करे और यह समाधान बिल्कुल अच्छा नहीं है; धन्यवाद। सादर –

1

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

, अपने ग्रिड हमेशा 8 कोशिकाओं है जब से मैं का उपयोग कर सकता है की सलाह देते हैं नेस्टेड LinearLayout रों (या आप सभी कोशिकाओं को ठीक उसी आकार, और अधिक जटिल TableLayout/TableRow कॉम्बो नहीं करना चाहते हैं) के बजाय:

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

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" 
     android:orientation="horizontal" 
     android:weightSum="1.0" > 

     <!-- Drop in 4 items here with layout_weight of 0.25 --> 

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" 
     android:orientation="horizontal" 
     android:weightSum="1.0" > 

     <!-- Drop in 4 items here with layout weight of 0.25 --> 

    </LinearLayout > 
</LinearLayout > 

यह एक निश्चित 2x4 ग्रिड बना देगा जो हमेशा स्क्रीन को भरता है।

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