键盘向上推动ListView

时间:2017-12-16 14:52:25

标签: android listview

我是Android UI设计的新手,所以请耐心等待。 在相对布局中,我有许多不同的控件 - TextView,ET,Button等,并在底部填充ListView。当焦点转到第一个输入字段(编辑文本)时,当键盘向上推动ListView并且它与其他字段重叠时。

下面是布局xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_orange_light"
    tools:context="com.as.myexpense.AddExpenseAct"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="81dp">

    <TextView
   android:id="@+id/tvShowExpnDate"
    android:layout_width="385dp"
    android:layout_height="19dp"
    android:allowUndo="true"
    android:autoSizeTextType="uniform"
    android:background="@color/colorAccent"
    android:fontFamily="sans-serif"
    android:foregroundTintMode="src_over"
    android:text="Expense for the date"
    android:textColor="@android:color/background_dark"
    android:textSize="12sp"
    android:textStyle="bold"
    tools:ignore="HardcodedText,MissingConstraints,RtlHardcoded,UnusedAttribute"
    tools:layout_editor_absoluteX="16dp"
    tools:layout_editor_absoluteY="7dp" />

    <TextView
    android:id="@+id/txtChangeExpenseDate"
    android:layout_width="88dp"
    android:layout_height="17dp"
    android:background="@android:color/holo_green_light"
    android:text="Change Date"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvShowExpnDate"
    tools:ignore="HardcodedText,MissingConstraints,RtlHardcoded"
    android:layout_below="@+id/tvShowExpnDate"
    android:layout_alignStart="@+id/etExpenseAmount" />

    <TextView
    android:id="@+id/tvAmount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/imgCategory"
    android:layout_below="@+id/txtChangeExpenseDate"
    android:text="Amount"
    android:textSize="20sp"
    app:layout_constraintTop_toBottomOf="@+id/tvShowExpnDate"
    tools:layout_editor_absoluteX="48dp" />

    <TextView
    android:id="@+id/tvExpenseCategory"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/imgCategory"
    android:layout_below="@+id/etExpenseAmount"
    android:text="Choose category"
    android:textSize="20sp"
    app:layout_constraintTop_toBottomOf="@+id/tvAmount"
    tools:ignore="HardcodedText,MissingConstraints"
    tools:layout_editor_absoluteX="48dp" />

    <EditText
    android:id="@+id/etExpenseAmount"
    android:layout_width="125dp"
    android:layout_height="40dp"
    android:ems="8"
    android:inputType="numberDecimal"
    android:labelFor="@+id/etExpenseAmount"
    app:layout_constraintLeft_toRightOf="@+id/tvAmount"
    app:layout_constraintTop_toBottomOf="@+id/tvShowExpnDate"
    app:srcCompat="@android:color/holo_orange_light"
    android:layout_alignTop="@+id/tvAmount"
    android:layout_toEndOf="@+id/imgCategory"
    android:layout_marginStart="12dp" />

    <ImageButton
    android:id="@+id/imgCategory"
    android:layout_width="75dp"
    android:layout_height="75dp"
    android:layout_alignStart="@+id/tvTotalExpense"
    android:layout_below="@+id/tvExpenseCategory"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvExpenseCategory"
    app:srcCompat="@android:color/holo_orange_light"
    tools:ignore="ContentDescription" />

    <EditText
    android:id="@+id/etShortDescription"
    android:layout_width="200dp"
    android:layout_height="39dp"
    android:layout_above="@+id/btnAddExpnToList"
    android:layout_marginBottom="10dp"
    android:layout_toEndOf="@+id/tvExpenseCategory"
    android:autoText="true"
    android:ems="10"
    android:hint="@string/short_description"
    android:inputType="textPersonName"
    android:maxLines="1"
    app:layout_constraintLeft_toRightOf="@+id/imgCategory"
    app:layout_constraintTop_toTopOf="parent"
    tools:ignore="Deprecated,LabelFor" />

    <Button
    android:id="@+id/btnAddExpnToList"
    android:layout_width="118dp"
    android:layout_height="50dp"
    android:layout_alignBottom="@+id/floatingActionButton"
    android:layout_alignParentStart="true"
    android:text="@string/Add"
    android:textColor="@android:color/background_dark"
    app:layout_constraintLeft_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/etShortDescription" />

    <Button
    android:id="@+id/btnCancel"
    android:layout_width="118dp"
    android:layout_height="50dp"
    android:layout_below="@+id/etShortDescription"
    android:layout_marginStart="17dp"
    android:layout_toEndOf="@+id/btnAddExpnToList"
    android:text="@string/Cancel"
    android:textColor="@android:color/background_dark"
    android:visibility="invisible"
    app:layout_constraintLeft_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/etShortDescription" />

    <ListView
    android:id="@+id/lvExpenses"
    android:layout_width="387dp"
    android:layout_height="312dp"
    android:layout_alignParentBottom="true"
    android:layout_alignStart="@+id/tvTotalExpense"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:background="?attr/colorButtonNormal"
    app:layout_constraintLeft_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btnAddExpnToList" />

    <TextView
    android:id="@+id/tvTotalExpense"
    android:layout_width="288dp"
    android:layout_height="20dp"
    android:layout_above="@+id/lvExpenses"
    android:layout_marginStart="10dp"
    android:text="Total expense "
    android:visibility="invisible"
    app:layout_constraintLeft_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btnAddExpnToList"
    tools:ignore="HardcodedText" />

    <android.support.design.widget.FloatingActionButton
    android:id="@+id/floatingActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/tvTotalExpense"
    android:layout_alignEnd="@+id/etShortDescription"
    android:layout_marginBottom="6dp"
    android:clickable="true"
    android:focusable="true"
    app:srcCompat="@android:color/holo_orange_dark" />

    <TextView
    android:id="@+id/tvExpnCatDisplay"
    android:layout_width="90dp"
    android:layout_height="20dp"
    android:layout_above="@+id/btnAddExpnToList"
    android:layout_alignStart="@+id/imgCategory"
    android:background="#00000000"
    android:textColor="@color/common_google_signin_btn_text_dark_focused"
    android:textSize="18sp"
    android:textStyle="normal|bold" />

    <TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/spTxnType"
    android:layout_below="@+id/tvShowExpnDate"
    android:layout_marginTop="9dp"
    android:text="@string/payment_type"
    android:textSize="18sp" />

    <Spinner
    android:id="@+id/spTxnType"
    android:layout_width="120dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView3"
    android:layout_toEndOf="@+id/btnCancel"
    android:entries="@array/txnType_name"
    android:spinnerMode="dialog"
    android:theme="@style/AlertDialog.AppCompat" />
    </RelativeLayout>

以下是截图:

On load of the screen

Expected view

1 个答案:

答案 0 :(得分:0)

“adjustResize”

活动的主窗口始终调整大小,以便为屏幕上的软键盘腾出空间。

“adjustPan”

活动的主窗口未调整大小以便为软键盘腾出空间。相反,窗口的内容会自动平移,以便键盘不会遮挡当前焦点,用户可以随时看到他们正在键入的内容。这通常不如调整大小,因为用户可能需要关闭软键盘才能进入并与窗口的模糊部分进行交互。

根据您的评论,在您的活动清单中使用以下内容