简体   繁体   中英

Adjust pan issue in android keyboard

So basically i want to push the bottom button to top of the keyboard and push the other content up after opening the keyboard. The problem is that if i use adjust pan the button overlap with the edit text and if i use the adjust resize button won't come up.

<LinearLayout
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="@color/white"
android:orientation="vertical"
tools:context="com.lifeincontrol.activities.home.AddCompanionActivity"
>
<android.support.v7.widget.Toolbar
  android:id="@+id/toolbar"
  android:layout_width="match_parent"
  android:layout_height="@dimen/toolbar_height"
  android:background="?attr/colorPrimary"
  android:titleTextColor="@android:color/white"
  app:popupTheme="@style/AppTheme.PopupOverlay"
  >
</android.support.v7.widget.Toolbar>
<ScrollView
  android:id="@+id/scroll_view"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fillViewport="true"
  >
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
  <ImageView
      android:id="@+id/companion_image"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="40dp"
      android:src="@drawable/ic_add_companion_illustration"
      />
  <LinearLayout
      android:id="@+id/number_field"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/companion_image"
      android:layout_marginLeft="15dp"
      android:layout_marginTop="62dp"
      android:orientation="horizontal"
      >
    <LinearLayout
        android:id="@+id/country_code_layout_before"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginBottom="7dp"
        android:orientation="vertical"
        >
      <LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          >
        <ImageView
            android:id="@+id/text_country_code_before"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginRight="12dp"
            android:drawableRight="@drawable/arrow_drop_down"
            android:src="@drawable/flag_in"
            />
        <ImageView
            android:id="@+id/drop_down_before"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingRight="12dp"
            android:paddingTop="12dp"
            android:src="@drawable/down_arrow_logging"
            />
      </LinearLayout>
      <View
          android:layout_width="match_parent"
          android:layout_height="1dp"
          android:layout_marginRight="12dp"
          android:layout_marginTop="4dp"
          android:background="#5E000000"
          />
    </LinearLayout>
    <EditText
        android:id="@+id/number_edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:hint="Phone Number"
        android:inputType="number"
        android:maxLines="1"
        android:textColorHint="#aaa"
       />
    <ImageView
        android:id="@+id/phone_book"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="11dp"
        android:src="@drawable/circle"
        android:visibility="gone"
        />
  </LinearLayout>
  <EditText
      android:id="@+id/name_edit_text"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/number_field"
      android:layout_marginLeft="16dp"
      android:layout_marginRight="16dp"
      android:layout_marginTop="30dp"
      android:hint="Name"
      android:imeActionLabel="Done"
      android:imeOptions="actionDone"
      android:maxLines="1"
      android:singleLine="true"
      android:textColorHint="#aaa"
      />
  <View
      android:layout_width="match_parent"
      android:layout_height="55dp"
      android:layout_below="@+id/name_edit_text"
      />
  <Button
      android:id="@+id/button_send"
      android:layout_width="match_parent"
      android:layout_height="55dp"
      android:layout_alignParentBottom="true"
      android:background="@color/companion_button_send"
      android:text="Send"
      android:textColor="@color/white"
      android:textSize="14sp"
      />
</RelativeLayout>
</ScrollView>
</LinearLayout>

first image before keyboard open

second image here i want to show the green button on top of keyboard

Add the below line to your activity java file

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

And then add a ScrollView to the layout. Remember ScrollView can hold only 1 child view.

<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <--------Your content---------->

  </RelativeLayout>

  </ScrollView>

1.change adjustpan to adjustResize in your menifest file like below

<activity android:name=".MainActivity"
            android:windowSoftInputMode="adjustResize|stateHidden"/>
  1. put your xml code inside scrollView

     <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <--------Your content----------> </RelativeLayout> </ScrollView> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM