简体   繁体   English

如何在表格布局中更改/调整EditText的大小?

[英]How to change/resize EditText in table layout?

I just want to resize the edittext so that it matches my texts. 我只想调整edittext的大小,使其与我的文本匹配。 When I insert an edittext in a table layout in column 3 it fills the whole space of column 3 and looks big. 当我在第3列的表格布局中插入edittext时,它会填满第3列的整个空间,看起来很大。 I want to change the size. 我想改变尺寸。 How is it possible? 这怎么可能? Below is my .xml coding: 下面是我的.xml编码:

<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>

I understand your problem... i tried using wrap_content etc .. but didnt work you have to manually set the height of the EditText.... here's the code: 我了解您的问题...我尝试使用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>

Try these, 试试这些

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.

you don't need to specify the column number it picks it itself just place it there if you want edit text to fit the space just strech the column 1&2 in table layout 您无需指定列号即可自行选择,只需要将其放置在此处即可,如果您想编辑文本以适合空间,只需在表格布局中拉伸第1和2列即可

or you can add linear layout as the table row and assign weight 或者您可以将线性布局添加为表格行并分配权重

Try 尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM