2012-06-09 63 views
4

我只是想調整edittext的大小,使它與我的文本相匹配。當我在第3列的表格佈局中插入edittext時,它填充了第3列的整個空間,看起來很大。我想改變尺寸。這怎麼可能? 下面是我的.xml編碼:如何更改/調整表格佈局中的EditText?

<TableRow> 
    <TextView 
     android:layout_column="1" 
     android:text="S" 
     android:layout_width="150dp" 
     /> 

    <TextView 
     android:layout_column="2" 
     android:text="C" 
     android:layout_width="75dp" /> 

    <TextView 
     android:layout_column="3" 
     android:text="G"/> 
</TableRow> 

<View 
    android:layout_height="2dip" 
    android:background="#FF909090" /> 

<TableRow> 
<TextView 
    android:layout_column="1" 
    android:id="@+id/s1" 
    android:text="Medium Text"/> 
<TextView 
    android:layout_column="2" 
    android:id="@+id/c1" 
    android:text="Text"/> 

<EditText 
    android:id="@+id/g1" 
    android:layout_column="3" /> 
</TableRow> 
+0

什麼你要?即時通訊有點困惑,你想改變寬度或高度? – Sajmon

回答

1

我理解你的p roblem ...我嘗試使用WRAP_CONTENT等。但你沒有工作手動設置的EditText的高度.... 下面的代碼:

<?xml version="1.0" encoding="utf-8"?> 

<TableRow 
    android:id="@+id/tableRow2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:weightSum="3" > 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/textView5" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="TextView" /> 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="fill_parent" 
     android:layout_height="15dp" 
     android:layout_weight="1" /> 



</TableRow> 
+0

是否奏效?讓我知道如果以後你碰到一種方式,而不是手動設置高度:) – Shark

0

你並不需要指定它撿起來列數自己只是把它放在那裏,如果你想編輯文本,以適應空間只是STRETCH時列1 & 2表格佈局

,也可以作爲錶行添加線性佈局和分配重量

0

嘗試

<EditText 
     android:layout_width="fill_parent" 
     android:id="@+id/txthwdxml" 
     android:layout_height="wrap_content" /> 
1

嘗試這些,

1. Set the "stretchColumn" property of table layout. 

2. Set the layout_width of the EditText to "wrap_content". 

3. If you want you can fix the size of the EditText by manually setting 
    the layout_width value in dp or dip.