2011-04-04 10 views
21

मैं 3x4 ग्रिड में 12 बटन बनाने के लिए टेबललेआउट का उपयोग करके एक फोन डायलर व्यू बनाने की कोशिश कर रहा हूं। मैं पंक्तियों को समान रूप से सभी उपलब्ध स्थान का उपयोग करने के लिए लंबवत रूप से फैलाना चाहता हूं, लेकिन ऐसा लगता है कि fill_parent TableRows पर काम नहीं करता है।एंड्रॉइड टेबलरो स्क्रीन को भरने के लिए लंबवत खिंचाव

मैं setMinimumHeight का उपयोग नहीं करना चाहता - क्या यह लेआउट में ठीक से करने का कोई तरीका है?

धन्यवाद बहुत बहुत,

एड

उत्तर

57
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="*" 
    > 
    <TableRow 
     android:layout_weight="1" 
     android:gravity="center"> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
    </TableRow> 
    <TableRow 
     android:layout_weight="1" 
     android:gravity="center"> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
    </TableRow> 
    <TableRow 
     android:layout_weight="1" 
     android:gravity="center"> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
    </TableRow> 
    <TableRow 
     android:layout_weight="1" 
     android:gravity="center"> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
     <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
    </TableRow> 
</TableLayout> 
</LinearLayout> 

enter image description here

+0

मैं 2 नेस्टेड Linearlayouts में बटन के साथ एक समाधान पोस्ट करने के लिए जा रहा था, लेकिन अपने समाधान भी ठीक काम करता है, और यह भी है लगता है ओपी के रूप में, एक tableLayout का उपयोग कर। :) – Adinia

+0

कूल, लेकिन जावा कोड में इसे कैसे करें? मैं केवल रनटाइम पर ज्ञात पंक्तियों और स्तंभों की संख्या के साथ समान परिणाम प्राप्त करने का प्रयास करता हूं, लेकिन 'java.lang.ArithmeticException: 'android.widget.TableLayout.mutateColumnsWidth (TableLayout.java:5279) में शून्य से विभाजित करें। यह भी विश्वास नहीं कर सकता कि एंड्रॉइड लेआउट सिस्टम वास्तव में बहुत मंद है। –

+1

ओह, मैंने इसे पाया है: http://stackoverflow.com/a/9683743/1418097 –

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