2012-09-05 13 views
12

मैं "निम्नलिखित मैच" एप्लिकेशन विकसित कर रहा हूं। आवेदन के लिए प्रयुक्त एक्सएमएल निम्नानुसार है:एंड्रॉइड: प्रोग्रामिंग के रूप में ग्रिडलाउट [ग्रिड व्यू नहीं] कैसे बनाएं?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/lytLinear" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/txtQuestion" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="30dp" 
     android:text="Match the following questions with their answers." /> 

    <GridLayout 
     android:id="@+id/lytGrid" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:columnCount="3" 
     android:columnWidth="300dp" 
     android:orientation="vertical" 
     android:rowCount="5" 
     android:stretchMode="columnWidth" > 

     <LinearLayout 
      android:id="@+id/Q1Lyt" 
      android:layout_width="160dp" 
      android:layout_height="50dp" 
      android:layout_column="0" 
      android:layout_row="0" 
      android:background="@drawable/shape_qn" 
      android:gravity="center" > 

      <TextView 
       android:id="@+id/Q1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_column="0" 
       android:layout_row="0" 
       android:text="Question1" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/A1Lyt" 
      android:layout_width="160dp" 
      android:layout_height="50dp" 
      android:layout_column="1" 
      android:layout_row="0" 
      android:background="@drawable/shape" 
      android:gravity="center" 
      android:text="Answer1" > 

      <TextView 
       android:id="@+id/A1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_column="0" 
       android:layout_row="0" 
       android:text="Answer1" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/Q2Lyt" 
      android:layout_width="160dp" 
      android:layout_height="50dp" 
      android:layout_column="0" 
      android:layout_row="1" 
      android:background="@drawable/shape_qn" 
      android:gravity="center" > 

      <TextView 
       android:id="@+id/Q2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Question2" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/A2Lyt" 
      android:layout_width="160dp" 
      android:layout_height="50dp" 
      android:layout_column="1" 
      android:layout_row="1" 
      android:background="@drawable/shape" 
      android:gravity="center" > 

      <TextView 
       android:id="@+id/A2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_column="0" 
       android:layout_row="0" 
       android:text="Answer2" /> 
     </LinearLayout> 
    </GridLayout> 
</LinearLayout> 

मैंने ग्रिड लेआउट बनाने के लिए निम्न कोड का प्रयास किया है। हालांकि, बच्चे रैखिक लेआउट के लिए, मैं प्रोग्रामेटिक रूप से एंड्रॉइड सेट करने का कोई तरीका नहीं ढूंढ पा रहा हूं: layout_column और android: layout_row पैरामीटर।

GridLayout gridLayout = new GridLayout(this); 
    gridLayout.setColumnCount(2); 
    gridLayout.setRowCount(15); 

    LinearLayout lyt1 = new LinearLayout(this); 
    LinearLayout.LayoutParams prmsLinLyt = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 

कोई पॉइंटर्स?

+0

मैं और जानकारी खोदने में सक्षम नहीं हूं। इसलिए, मैं इसके बजाय एक टेबल लेआउट का उपयोग कर रहा हूँ। – Srikanth

+10

मुझे यह नहीं पता कि यह सवाल क्यों बंद कर दिया गया है। मुझे लगता है कि यह एक त्रुटि है। अगर प्रश्न का उत्तर दिया गया तो इससे मेरी मदद की होगी। – Softlion

+4

var gridLayout पैराम्स = नया ग्रिडलाउटआउट .आउटआउट(); ग्रिडलायआउट पैराम्स। सेग ग्रेविटी (ग्रेविटीफ्लैग्स। भरें); ग्रिडलायआउट पैराम्स। RowSpec = GridLayout.InvokeSpec (iRow, 1); ग्रिडलायआउट पैराम्स। कॉलमस्पेक = ग्रिडलाउट। इन्वोकस्पेक (आईकॉल, 1); ग्रिड। एडव्यू (एवी व्यू, ग्रिडलायआउट पैराम्स); – Softlion

उत्तर

-3

आप इस प्रयास करना चाहिए:

gridLayout.setLayoutParams(prmsLinLyt); 

और यदि आप मान देना चाहता हूँ ...

LinearLayout.LayoutParams prmsLinLyt = new LinearLayout.LayoutParams(90,100); 

where layout_width = 90 
and layout_height= 100 
+0

धन्यवाद मुझे इसके बारे में पता है। लेकिन, मैं एंड्रॉइड के बराबर नहीं ढूंढ पा रहा हूं: layout_column और android: layout_row पैरामीटर। वे PrmsLinLyt के गुणों में दिखाई नहीं देते हैं। – Srikanth

7

यहाँ कैसे आप इसे प्रोग्राम के रूप में बना सकते हैं है:

GridLayout gridLayout = new GridLayout(getContext()); 

// Add Title 
GridLayout.Spec titleTxtSpecColumn = GridLayout.spec(2, GridLayout.BASELINE); 
GridLayout.Spec titleRowSpec = GridLayout.spec(0); 
TextView titleText = new TextView(getContext()); 
titleText.setText("Title"); 

gridLayout.addView(titleText, new GridLayout.LayoutParams(titleRowSpec , titleTxtSpecColumn)); 

के लिए अधिक जानकारी ApiDemos उदाहरण देखें।

+1

सभी पंक्तियों/कॉलम एक ही सेल में जोड़े गए हैं। – Softlion

+0

वास्तव में आप सही थे – Softlion

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