【问题标题】:edit text height getting decrease on click编辑文本高度在点击时减小
【发布时间】:2014-02-06 06:30:30
【问题描述】:

我在一个布局中有一个 editText 和一个列表视图。但是在单击 editText 时,它的高度会像这样减小

点击前:

点击时:

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent_clients_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffffff"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/search_button"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="5.0dip"
        android:layout_weight="0.9"
        android:background="@drawable/edbackground"
        android:drawableLeft="@drawable/search"
        android:drawablePadding="10.0dip"
        android:hint="search clients"
        android:textColor="@color/gray"
        android:textSize="15.0dip" />

    <ListView
        android:id="@+id/clients_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="5.0dip"
        android:layout_weight="0.1"
        android:background="@android:color/white" />

</LinearLayout>

【问题讨论】:

  • 只需将android:layout_height="wrap_content" 替换为android:layout_height="fill_parent" 并将android:layout_weight="0.9" 删除为EditText
  • M D 所说的那样去做。
  • @MD 谢谢它的工作:)

标签: android android-layout android-listview android-edittext


【解决方案1】:

只需将android:layout_height="wrap_content" 替换为android:layout_height="fill_parent" 并将remove android:layout_weight="0.9" 替换为EditText

【讨论】:

  • @Bansal_Sneha 如果有用,+1
【解决方案2】:

删除重量并放入wrap_content 以获得EditText 的高度

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent_clients_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffffff"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/search_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_launcher"
        android:drawableLeft="@drawable/ic_launcher"
        android:drawablePadding="10.0dip"
        android:hint="search clients"
        android:textColor="#123456"
        android:textSize="15.0dip" />

    <ListView
        android:id="@+id/clients_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="5.0dip"
        android:layout_weight="0.1"
        android:background="@android:color/white" />

</LinearLayout>

这应该可以工作

【讨论】:

  • 请告诉我应该用什么代替包装内容
  • @Bansal_Sneha 看到我的评论
【解决方案3】:

当您点击您的编辑文本时,会出现软输入,并且 android 有时会调整屏幕内容。这就是您的编辑文本看起来被裁剪的原因。为了防止这种情况,在您定义活动的Manifest.xml 中,在您的Activity 标签中添加以下行:-

android:windowSoftInputMode="adjustNothing"

这会起作用。

【讨论】:

  • 我在片段中使用这个布局。但是我得到了解决方案:)
  • @Bansal_Sneha 很好,也许这对其他人有帮助。 :)
猜你喜欢
  • 2011-09-17
  • 2014-11-17
  • 2018-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-12
  • 2014-06-18
  • 2017-06-29
相关资源
最近更新 更多