2014-09-18 31 views
0

当edittext单击后出现软键盘时,我遇到布局问题(edittext和button inside)。整个布局是rezising(变小)和元素内(edittext)要小。情况看起来像这样,我有2个布局,其中第一个需要50%的屏幕,下面是另外一个布局。在第二个布局中,我拥有所有editext和按钮,我希望布局保持原始大小 - 只需在出现键盘时将布局设置得更高。我尝试ajdustPan,adjustResize和其他,并不知道如何解决它。软键盘更改我的布局的大小

我在该布局中使用%来指定元素高度,同时我将ScrollView作为第一个布局,但这也不起作用。我的布局层次:

  • 滚动型
    • RelativeLayout的
      • 的RelativeLayout(50% - 空间大小)(alignBottom空间)
      • 空间
      • 的LinearLayout(50% - 空间大小)(layout_below空间)

在LinearLayout中,我有2个Edittext。

任何人都有建议吗?谢谢

回答

1

在清单文件中设置Activity:标签中的android:windowSoftInputMode =“stateUnchanged | adjustPan”。希望这会解决你的问题。

我已经尝试了.xml文件:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <RelativeLayout 
     android:id="@+id/top" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <ImageView 
      android:id="@+id/container" 
      android:layout_width="200dp" 
      android:layout_height="200dp" 
      android:layout_marginTop="50dp" 
      android:src="@drawable/ic_launcher" /> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/container" 
      android:layout_marginTop="50dp" 
      android:clickable="true" 
      android:onClick="removeFragment" 
      android:text="Remove" /> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/container" 
      android:layout_marginTop="50dp" 
      android:clickable="true" 
      android:onClick="removeFragment" 
      android:text="Remove" /> 
    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/top" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="50dp" 
      android:clickable="true" 
      android:onClick="removeFragment" 
      android:text="Remove" /> 

     <EditText 
      android:id="@+id/userName" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="50dp" 
      android:hint="Username" 
      android:imeOptions="actionDone" 
      android:inputType="text" 
      android:maxLines="1" 
      android:singleLine="true" /> 
    </LinearLayout> 
</RelativeLayout> 

清单文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.test" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="18" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.test.MainActivity" 
     android:windowSoftInputMode="stateUnchanged|adjustPan" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

+0

我已经尝试,不工作:/ – oro 2014-09-18 16:00:58

+0

我想你只是想在键盘打开时向上移动布局。 android:windowSoftInputMode =“stateUnchanged | adjustPan”对我来说工作正常。 – 2014-09-18 16:19:27

+0

是的,我想转移布局,但stateUnchanged | adjustPan,在我的情况下不能正常工作:/ – oro 2014-09-18 16:25:27