【问题标题】:EditText height-lengthEditText 高度-长度
【发布时间】:2013-09-02 16:58:15
【问题描述】:

我一直在尝试创建一个简单的记事本,但我无法在 xml 文件中创建一个匹配父级的 EditText

在xml中:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:ems="10" >

        <requestFocus />
    </EditText>

</TableLayout>

我希望全屏与editText匹配父级。

不是这样......我想要输入左对齐的文本

请帮忙!!:)

【问题讨论】:

    标签: android xml android-edittext notepad


    【解决方案1】:

    尝试将您的编辑文本布局宽度设置为 FILL_PARENT 或 MATCH_PARENT。

    【讨论】:

      【解决方案2】:

      将您的 android:layout_width="wrap_content" 更改为 android:layout_width="match_parent"

      更新 根据您更新的图像,这是因为您将父布局(表格布局)高度设置为与屏幕匹配。将其设置回包装内容,然后您将拥有所需的内容

      <?xml version="1.0" encoding="utf-8"?>
      <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" >
      
          <EditText
              android:id="@+id/editText1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:ems="10" >
      
              <requestFocus />
          </EditText>
      
      </TableLayout>
      

      这是结果

      【讨论】:

      • 好吧,我想要一个像第一张图片一样的编辑文本。第二张在中间插入文本...对不起,我的英语很差,希望你能理解我
      • 您检查过我在更新中发布的代码吗? TableLayoutlayout_heightwrap_content 而不是 match_parent
      • 不确定您所说的“中心”是什么意思。我上面的代码使文本左对齐。看看我的截图
      • @noobProgrammer 不妨将您之前的评论作为答案。这对我来说也是正确的解决方案。 :)
      【解决方案3】:

      我刚刚改变了重力: 使用以下code

        <RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
      
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_alignParentLeft="true"
              android:layout_alignParentRight="true"
              android:layout_alignParentTop="true"
              android:layout_weight="0.62" >
      
            <EditText
                android:id="@+id/editText1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:ems="10"
                android:gravity="left"
                android:inputType="textPersonName" >
                <requestFocus />
            </EditText>  
              </RelativeLayout>
      

      截图:

      :

      【讨论】:

        猜你喜欢
        • 2011-05-20
        • 1970-01-01
        • 2017-02-26
        • 1970-01-01
        • 1970-01-01
        • 2012-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多