【问题标题】:Why does edittext with empty text still have some height?为什么带有空文本的edittext仍然有一些高度?
【发布时间】:2014-06-24 19:31:06
【问题描述】:

我在另一个线程上研究了属性值 wrap_content 并发现它的功能是“强制 [视图] 仅扩展足以包含它包含的值(或子控件)。对于控件 - 例如文本框 ( TextView) 或图像 (ImageView) -- 这将包装正在显示的文本或图像。"(What's the difference between fill_parent and wrap_content?) 这是我的代码(用于空编辑文本

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Email"
        android:padding="5dp"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       />

</LinearLayout>

以及生成的布局(选择一个是编辑文本)http://imgur.com/6H8caKT

我的问题是,因为编辑文本不包含任何内容(空文本),不应该 wrap_ content 强制它没有高度?

【问题讨论】:

  • 用户需要能够打字。如果EditText 没有高度,他们就不能。因此,我假设EditText 强制执行最小单行高度。
  • 如果你想隐藏一个元素,看看这篇文章stackoverflow.com/questions/4480489/…
  • 不,我不想隐藏它。我只是好奇为什么这个东西在 wrap_content 之后仍然有高度
  • 评论有道理,没想到

标签: android android-edittext


【解决方案1】:

wrap_content 应该不同,一旦你默认 wrap_content 制作小部件,它会自动调整小部件,中,大屏幕等所有屏幕的小部件大小。 但是您提到了 dp 明智的,所有屏幕仅遵循 dp 值,但不会自动调整。

fill_parentmatch_parent 将与它们的父布局一起拉伸

【讨论】:

  • 请问这是对问题的回答吗?为什么有空的 EditText 与 wrap content height ?有什么办法解决这个问题?
  • @Renetik 我不确定,尝试从edittext中删除光标。
【解决方案2】:

我相信这是另一个 Android sdk“功能错误”。有 android:minLines=".." 并且它可以工作,但是由于我未知的原因,设置 0 被忽略,所以它始终保持为 1。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-19
    • 1970-01-01
    • 2021-04-27
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    • 2012-03-09
    • 2020-09-09
    相关资源
    最近更新 更多