【发布时间】:2016-05-19 16:03:18
【问题描述】:
我搜索了 NET,但没有找到解决问题的方法。我有一个很少 textViews 和 EditTexts 的表单。在屏幕底部,我放置了 3 个按钮。为了将它们固定在屏幕底部,我必须将它们放在滚动视图之外,如How to make a static button under a ScrollView? 中所述。
但是,当我在其中一个 edittext 中输入文本时打开软键盘时,按钮会向上移动到软键盘上方,覆盖一些 edittext 元素。
我希望按钮留在屏幕底部,以便软键盘覆盖它们。为了做到这一点,我必须将它们包含在滚动视图中,但是当软键盘关闭时,我无法将它们定位在屏幕底部。
这是我的 XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bgcolor"
android:orientation="vertical"
android:paddingTop="5dp">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:id="@+id/list_title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/xml_text_text"
android:textColor="@color/textColor"
android:visibility="gone" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:gravity="center"
android:padding="10dp"
android:text="@string/category_adding"
android:textColor="@color/myColor"
android:textSize="18sp"
android:textStyle="bold" />
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:isScrollContainer="true"
android:orientation="vertical"
android:visibility="visible">
<RelativeLayout
android:id="@+id/categoryLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:id="@+id/categoryQuestionNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/category_add_question_number"
android:textColor="@color/myColor"
android:textSize="18sp" />
<talkie.feedback.NumberPickerHorizontal
android:id="@+id/horizontal_number_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" />
<android.support.design.widget.TextInputLayout
android:id="@+id/questionPromptWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/categoryQuestionNumber"
android:layout_marginTop="2dp"
android:hint="@string/category_add_question">
<android.support.design.widget.TextInputEditText
android:id="@+id/questionPrompt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/user"
android:drawableStart="@drawable/user"
android:ems="45"
android:imeOptions="actionNext"
android:singleLine="true"
android:textColor="@color/myColor"
android:textSize="18sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/questionExplanationWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/questionPromptWrapper"
android:layout_marginTop="2dp"
android:hint="@string/category_add_explanation">
<android.support.design.widget.TextInputEditText
android:id="@+id/questionExplanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/user"
android:drawableStart="@drawable/user"
android:ems="45"
android:imeOptions="actionDone"
android:singleLine="true"
android:textColor="@color/myColor"
android:textSize="18sp" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/add"
android:layout_width="130dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/questionExplanationWrapper"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/border_round_corners_thin_mycolor_bkg"
android:text="@string/category_add_add_question"
android:textColor="@color/simple_white"
android:textSize="13sp"
android:textStyle="bold" />
<Button
android:id="@+id/delete"
android:layout_width="130dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/questionExplanationWrapper"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/border_round_corners_thin_mycolor_bkg"
android:text="@string/category_add_delete_question"
android:textColor="@color/simple_white"
android:textSize="13sp"
android:textStyle="bold" />
<RelativeLayout
android:id="@+id/categoryLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/delete"
android:layout_marginTop="2dp"
android:background="@drawable/border_round_corners_thin_blue"
android:padding="10dp"
android:visibility="visible">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/categoryLayout2"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="3">
<Button
android:id="@+id/save2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@drawable/btn_background"
android:text="@string/save_action"
android:textAllCaps="false"
android:textColor="@color/simple_white" />
<Button
android:id="@+id/return2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:background="@drawable/btn_background_blue"
android:text="@string/category_add_category"
android:textColor="@color/simple_white"
android:textStyle="bold" />
<Button
android:id="@+id/exit2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:background="@drawable/btn_background_exit"
android:text="@string/register_return"
android:textAllCaps="false"
android:textColor="@color/simple_white" />
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
在你的清单中,对于有问题的活动,使用
android:windowSoftInputMode="adjustPan" -
是的。但我在某处读到,与 adjustResize 相比,adjustPan 可能会导致问题。你能详细说明一下吗?
-
我在我的应用程序中使用 adjustPan 的原因与您描述的完全相同,并且没有问题。您能否详细说明“我在某处看到adjustPan 会导致问题”?你在哪里读到的?什么问题之王?