为什么我的XML文件中的EditText宽度不能使用fill_parent? [英] Why can't I use fill_parent on EditText's width in my XML file?

查看:80
本文介绍了为什么我的XML文件中的EditText宽度不能使用fill_parent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在EditText的宽度上使用fill_parent时,AndroidStudio的自动填充功能将其划掉.如果我仍然尝试使用它,则会将EditText放置在屏幕之外,从而弄乱了EditText的位置.我只想有一个简单的文本字段,然后在其旁边输入一个输入文本字段,它占据了屏幕的其余部分.

When I use fill_parent on the width of my EditText, the autofill of AndroidStudio shows it crossed out. If I still try using it it messes up the positioning of the EditText by throwing it out of the screen. I just want to have a simple text field and next to it an input text field which occupies the remaining of the screen.

这是代码:

<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kristmiha.registrationtest.MainActivity">

<TextView
    android:id="@+id/headline1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:gravity="center"
    android:text="@string/hello"
    android:textSize="32sp" />


<TextView
    android:id="@+id/headline2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/headline1"
    android:text="@string/register_here"
    android:gravity="center"
    android:textSize="24sp" />

<TextView
    android:id="@+id/tvFirstName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="First Name"
    android:layout_below="@+id/headline2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="20dp" />

<EditText
    android:id="@+id/etFirstName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/tvFirstName"
    android:layout_toRightOf="@+id/tvFirstName"
    android:layout_toEndOf="@+id/tvFirstName" />

这是文本字段的位置:

Here is the position of the text field:

推荐答案

fill_parent值已弃用,请使用match_parent

此处,您可以看到更多内容,并

Here you can see more and here more

视图请求的高度或宽度的特殊值. FILL_PARENT 表示视图要与父视图一样大,减去 父母的填充物(如果有).从API开始不推荐使用此值 级别8,并由MATCH_PARENT代替.

Special value for the height or width requested by a View. FILL_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. This value is deprecated starting in API Level 8 and replaced by MATCH_PARENT.

对于您的问题:您应该使用此:

For your problem : you should use this:

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="test.com.temp.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="label"
        android:id="@+id/labelOne"
        android:layout_alignBaseline="@+id/input"
        />
    <EditText
        android:id="@+id/input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/labelOne"
        android:layout_toEndOf="@+id/labelOne"
        />
</RelativeLayout>

这篇关于为什么我的XML文件中的EditText宽度不能使用fill_parent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆