【问题标题】:Android - Button Keeps overlapping EditextAndroid - 按钮保持重叠的Edittext
【发布时间】:2014-05-04 19:41:11
【问题描述】:

我正在制作一个 android 应用程序,其中有一个活动,顶部有一个 EditText,底部有三个 Buttons。我在清单中将android:windowSoftInputMode="adjustResize" 设置为活动,以便在使用虚拟键盘时自动调整大小。但是,当我在EditText 中输入一个长句子时,它的大小会增加并且低于Buttons。我希望 EditText 仅扩展到 3 个 Buttons 和 ActionBar 之间的可用空间。

这是发生了什么 -

这是活动的 XML 代码 -

<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:background="#eaeaea"
    tools:context=".AddNoteEditor" >

<EditText
    android:id="@+id/noteEditor"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:background="@drawable/card"
    android:ems="10"
    android:hint="@string/nn"
    android:inputType="textMultiLine"
    android:padding="12.5dp"
    android:singleLine="true"
    android:textSize="19dp" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onClickAddNote"
    android:text="@string/ok"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true" />

<ToggleButton
    android:id="@+id/highlighter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button1"
    android:layout_alignBottom="@+id/button1"
    android:layout_toLeftOf="@+id/button2"
    android:layout_toRightOf="@+id/button1"
    android:text="@string/hglt"
    android:textOff="Highlighting Off"
    android:textOn="Highlighting On" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onClickDiscardNote"
    android:text="@string/cancel"
    android:layout_alignTop="@+id/highlighter"
    android:layout_alignParentRight="true" />

</RelativeLayout>

提前致谢。

【问题讨论】:

    标签: android android-layout android-edittext android-button


    【解决方案1】:

    问题在于相对布局,当文本足够长时,EditText 会填满整个可用空间(在此布局中)。因此,它也填充了这些按钮下方的空间。

    您基本上有两种解决方案。

    1. 为 EditText 添加一个底部边距,其大小与按钮的高度相同。

    2. 使用线性布局而不是相对布局(一个线性布局替换相对布局 - 垂直布局,另一个线性布局 - 水平 - 并排放置这些按钮)。

    【讨论】:

      【解决方案2】:

      也许您必须尝试将您的EditText 设为可滚动:

      水平滚动:

       <EditText
            android:scrollHorizontally="true"
       ../>
      

      垂直滚动:

      <EditText
           android:scrollbars = "vertical"
      ../>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-10
        相关资源
        最近更新 更多