【问题标题】:How to change/resize EditText in table layout?如何在表格布局中更改/调整 EditText 的大小?
【发布时间】:2012-06-09 06:02:02
【问题描述】:

我只想调整编辑文本的大小,使其与我的文本匹配。当我在第 3 列的表格布局中插入编辑文本时,它会填充第 3 列的整个空间并且看起来很大。我想改变尺寸。这怎么可能? 下面是我的 .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>

【问题讨论】:

  • 你想要什么?我有点困惑,你想改变宽度或高度吗?

标签: java android xml android-edittext


【解决方案1】:

我了解您的问题...我尝试使用 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>

【讨论】:

  • 成功了吗??让我知道您以后是否遇到手动设置高度以外的其他方法:)
【解决方案2】:

试试这些,

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.

【讨论】:

    【解决方案3】:

    你不需要指定它自己选择的列号,如果你想编辑文本以适应空间,只需将它放在那里,只需在表格布局中拉伸第 1 列和第 2 列

    或者您可以将线性布局添加为表格行并分配权重

    【讨论】:

      【解决方案4】:

      试试

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-09-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-12
        • 1970-01-01
        相关资源
        最近更新 更多