簡體   English   中英

將布局移至軟鍵盤上方

[英]Move layout above soft keyboard

我試圖用谷歌搜索我的問題,但是找不到任何可以幫助我的東西,或者我只是聽不懂。 我想在打開軟鍵盤時將一些控件移到上方,這是否可能。 具體來說,我想將所有內容都移到login_btnLogin上方,包括當軟鍵盤彈出時也包含此按鈕。

<?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:background="@drawable/background"
android:padding="10dp" >

<ImageView
    android:id="@+id/login_img_logo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="40dp"
    android:layout_marginTop="30dp"
    android:contentDescription="@string/app_name"
    android:scaleType="center"
    android:src="@drawable/logo" >
</ImageView>

<RelativeLayout
    android:id="@+id/login_loginLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/login_img_logo"
    android:background="@drawable/rounded_edittext_with_gray_borderline"
    android:paddingBottom="5dp" >

    <EditText
        android:id="@+id/login_txt_username"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/rounded_edittext_without_borderline"
        android:ems="10"
        android:gravity="center_vertical"
        android:hint="@string/register_username"
        android:inputType="text"
        android:textColor="@android:color/black" >

    </EditText>

    <View
        android:id="@+id/login_separator"
        android:layout_width="wrap_content"
        android:layout_height="1dp"
        android:layout_below="@+id/login_txt_username"
        android:background="@android:color/darker_gray" />

    <EditText
        android:id="@+id/login_txt_password"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/login_txt_username"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignRight="@+id/login_txt_username"
        android:layout_below="@+id/login_separator"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="@drawable/rounded_edittext_without_borderline"
        android:gravity="center_vertical"
        android:hint="@string/register_password"
        android:inputType="textPassword"
        android:textColor="@android:color/black" >

    </EditText>
</RelativeLayout>

<LinearLayout
    android:id="@+id/login_buttonslayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/login_loginLayout"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="15dp"
    android:gravity="center_horizontal" >

    <Button
        android:id="@+id/login_btnLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:background="@drawable/button"
        android:gravity="center"
        android:text="@string/login"
        android:textColor="#000000"
        android:textSize="20sp"
        android:textStyle="bold" 
        />


</LinearLayout>

<RelativeLayout
    android:id="@+id/login_bottom_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/login_buttonslayout"
    android:layout_marginBottom="10dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/login_txt_forgot_password"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:gravity="center_horizontal"
        android:text="@string/forgotPassword"
        android:textColor="@android:color/background_dark"
        android:textSize="15sp"
        android:textStyle="bold" >

    </TextView>

    <Button
        android:id="@+id/login_btn_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@string/forgotPassword"
        android:background="@drawable/info"
        android:textAppearance="?android:attr/textAppearanceSmallInverse"
        android:textColor="@android:color/primary_text_light" />

</RelativeLayout>

</RelativeLayout>

用這個

在Manifest.xml中:

android:configChanges="keyboardHidden|orientation"

android:windowSoftInputMode="adjustPan"

讓我知道同時使用這對您是否有幫助,還可以在您的虛擬鍵盤造成問題的布局中使用scrollview,這也有一定幫助

嘗試使用此方法:這將適用於所有設備。

android:configChanges="orientation|screenSize|keyboardHidden"

而且您仍然遇到問題,然后嘗試將其添加到清單文件中

android:windowSoftInputMode="stateAlwaysHidden"

嘗試使EditText集中注意力,以便在第一時間解決布局問題。

暫無
暫無

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

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