简体   繁体   English

调整Android键盘中的声相问题

[英]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 将以下行添加到您的活动Java文件中

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

And then add a ScrollView to the layout. 然后将ScrollView添加到布局。 Remember ScrollView can hold only 1 child view. 请记住,ScrollView只能容纳1个子视图。

<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 1,更改adjustpan以在清单文件中调整resize,如下所示

<activity android:name=".MainActivity"
            android:windowSoftInputMode="adjustResize|stateHidden"/>
  1. put your xml code inside scrollView 将您的xml代码放入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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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