3

我一直在尝试创建一个简单的记事本,但无法在 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匹配父级。

不像这样......我想要以左对齐方式输入的文本

PICC

请帮忙!!:)

4

3 回答 3

1

将您的更改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>

这是结果

在此处输入图像描述

于 2013-09-02T17:03:29.420 回答
1

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

于 2013-09-02T17:11:55.163 回答
0

我只是改变了重力: 使用以下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>

截屏:

截屏

于 2013-11-01T11:10:33.433 回答