1

所以基本上我想将底部按钮推到键盘顶部,然后在打开键盘后将其他内容向上推。问题是,如果我使用调整平移按钮与编辑文本重叠,并且如果我使用调整调整大小按钮将不会出现。

<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>

键盘打开前的第一张图片

第二张图片我想在键盘顶部显示绿色按钮

4

2 回答 2

0

将以下行添加到您的活动 java 文件中

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

然后在布局中添加一个 ScrollView。记住 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>
于 2017-11-10T06:44:16.253 回答
0

1.将您的清单文件中的adjustpan更改为adjustResize,如下所示

<activity android:name=".MainActivity"
            android:windowSoftInputMode="adjustResize|stateHidden"/>
  1. 将您的 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>
    
于 2017-11-10T06:48:50.453 回答