2011-01-01 15 views
11

मेरे पास नीचे एक बटन के साथ एक टेबललाउट है। मेरी समस्या यह है कि बटन कॉलम की पूरी चौड़ाई को भरने के लिए फैला हुआ है, भले ही मैं इसे चौड़ा नहीं चाहता।एंड्रॉइड टेबललेआउट में बटन चौड़ाई

alt text

एक्सएमएल इस तरह दिखता है:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:stretchColumns="*" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <TableRow android:layout_height="wrap_content" 
     android:layout_width="fill_parent"> 
    <CheckBox android:id="@+id/check1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Some text 1"/> 
    <CheckBox android:id="@+id/check2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Some text 1"/> 
    </TableRow> 
    <TableRow android:layout_height="wrap_content" 
     android:layout_width="fill_parent"> 
    <CheckBox android:id="@+id/check3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Even some more text 2"/> 
    <CheckBox android:id="@+id/check4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Even some more text 2"/> 
    </TableRow> 
    <TableRow android:layout_height="wrap_content" 
     android:layout_width="fill_parent"> 
    <CheckBox android:id="@+id/check5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="An even longer line of text 3"/> 
    <CheckBox android:id="@+id/check6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Another longer line of text 3"/> 
    </TableRow> 

    <EditText 
     android:id="@+id/myEditText1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textMultiLine" 
     android:singleLine="false" 
     android:text="Enter some text" 
    /> 

    <TableRow> 
    <Button android:id="@+id/SaveButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Save"> 
    </Button> 
    </TableRow>  

</TableLayout> 

यहां तक ​​कि अगर मैं बटन यह ध्यान नहीं देता का सुस्पष्ट चौड़ाई निर्धारित किया है। उदाहरण के लिए अगर मेरे पास है:

<Button android:id="@+id/SaveButton" 
     android:layout_width="100sp" 
     android:layout_height="100sp" 
     android:text="Save"> 
    </Button> 

... बटन लम्बे हो जाता है, लेकिन अभी भी चौड़ाई कॉलम भरने के लिए फैला है।

मैं चाहता हूं कि बटन कॉलम में केंद्रित वर्तमान की चौड़ाई के आधा हो। अग्रिम धन्यवाद !!

उत्तर

20

@mbaird सही है: android:stretchColumns="*" हमेशा कॉलम की चौड़ाई को फैलाने जा रहा है। हालांकि, आप अभी भी कॉलम के अंदर इच्छित व्यवहार प्राप्त कर सकते हैं जो कॉलम में फ्रेमलेआउट डालने वाले कॉलम में डालकर कॉलम की चौड़ाई फैलाता है, और उसके बाद अपना बटन वहां अंदर रखता है। तो फिर तुम जैसे आप चाहें और FrameLayout भीतर यह केंद्र बटन के आकार बना सकते हैं:

<TableRow> 
    <FrameLayout 
     android:layout_height="wrap_content"> 
     <Button 
      android:id="@+id/SaveButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:paddingLeft="40dp" 
      android:paddingRight="40dp" 
      android:text="Save"> 
     </Button> 
    </FrameLayout> 
</TableRow> 
3

मुझे यकीन है कि android:stretchColumns="*" हमेशा बटन को इस तरह फैलाएगा। क्या आपने टेबललेआउट के बाहर बटन डालने पर विचार किया है?

प्रलेखन से: टेबललेआउट के बच्चे लेआउट_विड्थ विशेषता निर्दिष्ट नहीं कर सकते हैं। चौड़ाई हमेशा MATCH_PARENT है। हालांकि, लेआउट_हेइट विशेषता को बच्चे द्वारा परिभाषित किया जा सकता है; डिफ़ॉल्ट मान WRAP_CONTENT

+0

इस समाधान के साथ समस्या यह है कि, स्तंभ के भीतर बटन केंद्र के लिए मुश्किल है, तो बटन स्तंभ के बाहर है । –

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