打开键盘时,带有alignParentBottom属性的视图覆盖Edittext

时间:2019-08-30 00:07:12

标签: android android-layout

我有一个Fragment,其中嵌套了fragments,使用的是Viewpager。键盘打开后,RelativeLayout会覆盖EditText

relative layout with <code>viewpagerindicator</code> covering the <code>EditText</code>

RelativeLayout上升的情况下,有没有办法打开键盘?

父级Fragment布局:

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:background="@color/colorBackground"
    android:layout_height="match_parent">

  <android.support.v4.view.ViewPager
      android:id="@+id/vp_service_creation"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

   <RelativeLayout
        android:id="@+id/rr_semi_circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="-180dp"
        android:layout_centerInParent="true"
        android:background="@drawable/half_circle_green"
        android:layout_weight="1">

        <dk.ostebaronen.droid.viewpagerindicator.CirclePageIndicator
           android:id="@+id/pi_circles"
           android:layout_marginTop="40dp"
           android:layout_centerInParent="true"
           android:layout_alignParentTop="true"
           android:layout_height="wrap_content"
           android:layout_width="90dp"
        />
    </RelativeLayout>
</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

我为您的案件尝试了不同的方法。

选项1:

您可以尝试adjustNothing,但键盘可能会覆盖您的EditText。

<application ... >
    <activity
        android:windowSoftInputMode="adjustNothing" ... >
        ...
    </activity>
    ...
</application>

您可以参考教程here

选项2:

如果您想保留adjustPan以便在键盘覆盖EditText时自动向上推视图,建议您添加一个侦听器以检测键盘的可见性。当键盘可见时,隐藏rr_semi_circle布局。当用户完成输入文本和键盘的隐藏时,请再次显示rr_semi_circle布局。

答案 1 :(得分:0)

在下面的示例中添加ScrollView。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/colorBackground"
android:layout_height="match_parent">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

<android.support.v4.view.ViewPager
  android:id="@+id/vp_service_creation"
  android:layout_width="match_parent"
  android:layout_height="match_parent" />

<RelativeLayout
    android:id="@+id/rr_semi_circle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="-180dp"
    android:layout_centerInParent="true"
    android:background="@drawable/half_circle_green"
    android:layout_weight="1">

    <dk.ostebaronen.droid.viewpagerindicator.CirclePageIndicator
       android:id="@+id/pi_circles"
       android:layout_marginTop="40dp"
       android:layout_centerInParent="true"
       android:layout_alignParentTop="true"
       android:layout_height="wrap_content"
       android:layout_width="90dp"
    />
   </RelativeLayout>
  </ScrollView>

</RelativeLayout>