我有一个相当简单的登录页面在我的Android应用程序,包含标题,用户名TextView的,密码的TextView,登录按钮和图像页脚:如何避免键盘启动或方向改变时Android界面的变化?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff" >
<!-- Header Starts -->
<LinearLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<!-- Logo Start -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:src="@drawable/header" />
<!-- Logo Ends -->
</LinearLayout>
<!-- Header Ends -->
<!-- Footer Start -->
<LinearLayout android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:layout_alignParentBottom="true"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:src="@drawable/footer" />
</LinearLayout>
<!-- Footer Ends -->
<!-- Login Form -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip"
android:layout_below="@+id/header"
>
<!-- Application Name Label -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:gravity="center"
android:padding="10dip"
android:textSize="25dp"
android:textStyle="bold"
/>
<!-- Username Label -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="User Name"
android:textColor="#372c24" />
<EditText
android:id="@+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_marginTop="5dip"
android:singleLine="true" />
<!-- Password Label -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Password"
android:textColor="#372c24" />
<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_marginTop="5dip"
android:password="true"
android:singleLine="true" />
<!-- Login button -->
<Button
android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Logon" />
</LinearLayout>
<!-- Login Form Ends -->
</RelativeLayout>
</ScrollView>
我有两个问题,我认为是相关的:
- 当键盘向上时,向下滚动时,我看到图像页脚“隐藏”在登录按钮后面,而不是停留在它下面。
- 屏幕水平取向时也是如此。
我试过的东西:
- 设置在活动
android:windowSoftInputMode="adjustPan"
,但我希望能够向下滚动键盘出现时,或android:windowSoftInputMode="adjustResize"
,或任何其他参数有关此事。 - 在按钮中设置
marginBottom
。
都没有工作。 我将不胜感激任何帮助。
您是否也指我应该在onConfigurationChanged方法中写入内容?因为我不知道在配置更改时要更改什么......只有编写您的建议不起作用......谢谢 – MichalK 2012-08-02 10:44:55