【发布时间】:2015-08-21 18:39:17
【问题描述】:
我设计的登录布局如下
<?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/login_bg">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="@+id/login_fields_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<ImageView
android:id="@+id/loginLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="30dp"
android:src="@drawable/logo" />
<EditText
android:id="@+id/userNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:background="@drawable/textfield"
android:drawableLeft="@drawable/username"
android:drawablePadding="10dip"
android:hint="@string/hint_username"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLength="50"
android:padding="10dp"
android:singleLine="true"
android:textColor="@color/login_textcolor"
android:textCursorDrawable="@null" />
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@drawable/textfield"
android:drawableLeft="@drawable/password"
android:drawablePadding="10dip"
android:hint="@string/hint_password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:padding="10dp"
android:singleLine="true"
android:textColor="@color/login_textcolor"
android:textCursorDrawable="@null" />
<LinearLayout
android:id="@+id/loginOptionsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<CheckBox
android:id="@+id/rememberMeCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:checked="false"
android:drawableEnd="@drawable/bg_checkbox"
android:gravity="center_vertical"
android:paddingRight="40dp"
android:text="@string/text_rememberme"
android:textColor="@color/login_textcolor"
android:textSize="14sp" />
<Button
android:id="@+id/forgotPasswordButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:gravity="right|center_vertical"
android:singleLine="true"
android:text="@string/text_forgotpassword"
android:textColor="@color/login_textcolor"
android:textSize="14sp" />
</LinearLayout>
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="@drawable/button_bg"
android:text="@string/text_login"
android:textColor="@android:color/white"
android:textSize="20dp"
android:textStyle="bold" />`
</LinearLayout>
</ScrollView>
</RelativeLayout>
当我触摸edittext时,背景向上移动它需要保持不变,因为它在滚动视图之外。如何解决这个问题。
我提到了以下内容 Background Image Placement 因为他们需要在底角我需要它作为背景。但无论如何我好奇地尝试了它,但它仍然在滚动背景
【问题讨论】:
-
@nkorth 位于左下角。在我的场景中,它是整个背景。
-
是的,您可以使用相同的技术将整个背景锚定到顶部边缘。我认为您的情况是:默认情况下背景锚定在中心,这意味着当视口缩小时(由于键盘),背景似乎会移动。如果背景固定在顶部,则高度变化不会移动背景。
-
我也试过了,它不工作它正在将背景更多地放在顶部。它不应该向上移动背景应该是恒定的。
-
@nkorth 你能试试这个代码,然后按上下箭头。 annitha Manikandan 给出的答案是有效的。
标签: android layout android-edittext scrollview android-relativelayout