簡體   English   中英

調整Android鍵盤中的聲相問題

[英]Adjust pan issue in android keyboard

所以基本上我想將底部的按鈕按到鍵盤的頂部,然后在打開鍵盤后將其他內容向上推。 問題是,如果我使用調整平移按鈕,則該按鈕與編輯文本重疊,如果使用調整大小調整按鈕,則不會出現。

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

鍵盤打開前的第一張圖片

第二張圖片我想在鍵盤頂部顯示綠色按鈕

將以下行添加到您的活動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>

1,更改adjustpan以在清單文件中調整resize,如下所示

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM