簡體   English   中英

顯示鍵盤時如何調整布局大小

[英]how to resize the layout when keyboard is shown

當鍵盤彈出時,布局不完全可見。我已經嘗試了很多示例,但是它不起作用。任何幫助將不勝感激。謝謝,我的manifest.xml文件是

       <activity
        android:name=".activity.SignUp"
        android:windowSoftInputMode="stateVisible|adjustResize"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="portrait"
        />
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

我的布局文件是

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:focusableInTouchMode="false"
android:orientation="vertical">


<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="40dp"
    android:src="@drawable/userprofile" />

<EditText
    android:id="@+id/editText"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginBottom="-10dp"
    android:layout_marginLeft="80dp"
    android:hint="USERNAME"
    android:inputType="textPersonName"
     />

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editText"
    android:layout_marginLeft="39dp"
    android:layout_marginTop="30dp"
    android:src="@drawable/email" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView3"
    android:layout_alignLeft="@+id/editText"
    android:layout_alignStart="@+id/editText"
    android:hint="ENTER EMAIL"
    android:inputType="textEmailAddress"
    />

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView3"
    android:layout_marginLeft="39dp"
    android:layout_marginTop="20dp"
    android:src="@drawable/passunlock" />

<EditText
    android:id="@+id/editText3"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageView4"
    android:layout_marginLeft="80dp"
    android:layout_marginTop="-15dp"
    android:hint="ENTER PASSWORD"
    android:inputType="textPassword"
    android:text="password" />

<ImageView
    android:id="@+id/imageView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/imageView6"
    android:layout_alignLeft="@+id/imageView4"
    android:layout_alignStart="@+id/imageView4"
    android:src="@drawable/password" />

<EditText
    android:id="@+id/editText4"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editText3"
    android:layout_marginLeft="80dp"
    android:layout_marginTop="10dp"
    android:hint="RETYPE PASSWORD"
    android:inputType="textPassword"
    android:text="password" />

<ImageView
    android:id="@+id/imageView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editText4"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="39dp"
    android:src="@drawable/signup" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView6"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="10dp"
    android:text="SIGN UP"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@android:color/white" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginRight="-14dp"
    android:layout_toLeftOf="@+id/imageView6"
    android:layout_toStartOf="@+id/imageView6"
    android:src="@drawable/username" />

將Window SoftInput Mode屬性設置為AdjustPan和AdjustResize

<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>  OR
<activity android:windowSoftInputMode="adjustResize"> </activity>  OR
<activity android:windowSoftInputMode="adjustPan"> </activity>

如果以上任何方法均無效,請在onCreate()方法中使用以下代碼:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

下面的鏈接可能會幫助您

https://developer.android.com/training/keyboard-input/visibility.html

如果adjustResize不起作用,請嘗試將ScrollView添加為父布局。

暫無
暫無

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

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