背景正在滚动它应该是恒定的?
background is scrolling it should be constant?
我设计的登录布局如下
<?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>
当我触摸编辑文本时,背景会向上移动,因为它在 scrollview.How 之外,所以它需要保持不变才能解决这个问题。
我参考了以下内容
Background Image Placement
因为他们需要在底角我需要它作为 background.but 无论如何我出于好奇尝试了它但它仍然在滚动背景
在您的 activity
中使用以下内容
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
我试过了,很管用。从 xml 布局
中移除背景
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
getWindow().setBackgroundDrawableResource(R.drawable.login_bg) ;
我设计的登录布局如下
<?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>
当我触摸编辑文本时,背景会向上移动,因为它在 scrollview.How 之外,所以它需要保持不变才能解决这个问题。
我参考了以下内容 Background Image Placement 因为他们需要在底角我需要它作为 background.but 无论如何我出于好奇尝试了它但它仍然在滚动背景
在您的 activity
中使用以下内容getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
我试过了,很管用。从 xml 布局
中移除背景getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
getWindow().setBackgroundDrawableResource(R.drawable.login_bg) ;