【问题标题】:EditText box height issue androidEditText框高度问题android
【发布时间】:2011-07-26 05:46:39
【问题描述】:

我有一个linearlayout,其中有一个图像视图、一个textview、两个edittext 和按钮。

当我在模拟器或设备中运行我的应用程序时,edittexts 的高度似乎更大,而不是它们应该是单行 edittext 框。

我的 layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@android:color/white">
    <TextView android:id="@+id/item_blank" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:padding="2dp" 
        android:textSize="14dp" 
        android:textColor="@android:color/black"
        android:background="@android:color/white" 
        android:text=" "/>
    <ImageView android:id="@+id/test_image" 
        android:src="@drawable/logo_infraline_energy"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center"/>
    <TextView android:id="@+id/item_title" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:padding="2dp" 
        android:textSize="14dp" 
        android:textColor="@android:color/black"
        android:background="@android:color/white" 
        android:text="Please put in your valid credentials to get access."/>
    <EditText android:id="@+id/userName" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:inputType="textEmailAddress" 
        android:layout_weight="1" 
        android:height="30dp"
        android:hint="Email Address" />
    <EditText android:id="@+id/password" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="1"
        android:hint="Password"
        android:height="30dp" 
        android:password="true" />
    <Button android:id="@+id/loginButton" 
        android:text="Login"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:onClick="login" />
</LinearLayout>

【问题讨论】:

    标签: android android-layout android-edittext


    【解决方案1】:

    删除线:

    android:layout_weight="1"

    来自 EditTexts 和您的 EditTexts 将是单行的。干杯。

    【讨论】:

      【解决方案2】:

      这是因为您为 EditText 赋予了 1 的权重。这告诉父 LinearLayout 增大 EditText 以填充剩余的任何空白空间。只需删除 weight=1 就可以了:)

      【讨论】:

        【解决方案3】:

        它的 weight=1 以及 height=30px。 layout_height=wrap_content 被 weight=1 和 height=30px 破坏。摆脱两者,您将拥有所需的布局

        【讨论】:

          【解决方案4】:

          只需输入android:layout_height="20px" 而不是android:layout_height="wrap_content"

          并删除android:layout_weight="1"

          看看editText是否会改变大小。

          【讨论】:

            猜你喜欢
            • 2013-02-28
            • 2011-05-20
            • 1970-01-01
            • 2013-07-06
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多