2013-02-21 210 views
1

我試圖谷歌我的問題,但找不到任何可以幫助我,或者我只是不明白。 我想在軟鍵盤上方打開一些控件,這是可能的。具體而言,我想移動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> 
+0

你能找到解決問題的方法嗎? – Hamid 2014-02-20 19:55:38

回答

0

使用本

在的Manifest.xml:

android:configChanges="keyboardHidden|orientation" 

android:windowSoftInputMode="adjustPan" 

讓我知道同時使用這對您有所幫助或不和也在使用滾動視圖您的虛擬鍵盤正在創建的佈局問題也有所幫助

+0

我已經嘗試了軟輸入模式,但是id沒有幫助。我還將scroll_view中的所有內容放在了login_bottom_layout之上,但它移動了login_bottom_layout,其餘的視圖保持原樣。 – Damir 2013-02-21 13:51:23

0

試試這個:這適用於所有設備。

android:configChanges="orientation|screenSize|keyboardHidden" 

而且你仍然得到那麼問題嘗試添加該清單檔案中的

android:windowSoftInputMode="stateAlwaysHidden" 

儘量集中你的EditText所以在拳頭時間,使您的佈局問題能夠得到解決。

+0

我的應用程序屏幕方向始終爲縱向,screenSize不可識別,keyboardHidden-我應該如何處理此更改?我試圖把重點放在edittext,但它只是移動edittext,而不是整個佈局 – Damir 2013-02-21 14:28:25

+0

錯誤,它不工作! – 2014-10-02 21:35:17