如何防止在edittext焦点上滚动。如果您知道约束或片段,请给我一条正确的路径。
注意:1。我有两个片段。 我在任何地方都没有使用任何类型的滚动视图。 3.我正在使用约束布局进行UI设计。
工作流:
第一个片段:我正在替换第一个
FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager(); FragmentTransaction ft = getSupportFragmentManager()。beginTransaction(); ft.replace(R.id.fragment_container,first_fragment); ft.commitAllowingStateLoss();
FragmentManager fragment = getActivity()。getSupportFragmentManager(); FragmentTransaction fragmentTransactionlogin = fragment.beginTransaction(); fragmentTransactionlogin.add(R.id.fragment_container,second_fragment," tag"); fragmentTransactionlogin.commit();
问题:这一切都运行正常,但是当我的第二个片段打开时,它们是两个编辑文本,所以当我按下(焦点)时,我的所有布局都在向上移动。
这是我的第二个片段xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:rsv="http://schemas.android.com/tools"
android:id="@+id/signupcoordinatorLayout"
android:layout_width="match_parent"
android:clickable="true"
android:layout_height="match_parent"
android:background="@drawable/background_login"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/view3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:visibility="gone"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_fragment" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/loginLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.constraint.Guideline
android:id="@+id/guideline_ver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
<android.support.constraint.Guideline
android:id="@+id/guideline_hor_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.3" />
<android.support.constraint.Guideline
android:id="@+id/guideline_hor_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.8" />
<ImageView
android:id="@+id/splashMainresImage"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/txt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:text="@string/loginTag"
android:textColor="@color/white"
android:textSize="@dimen/login_text_medium_size"
app:layout_constraintBottom_toTopOf="@+id/inputUserEmail"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="@+id/inputUserEmail"
android:layout_width="match_parent"
android:layout_height="@dimen/mediumheight"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:background="@drawable/edit_text_bg"
android:hint="@string/email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="@color/text"
android:textColorHint="@color/text"
android:textSize="@dimen/login_text_size"
app:layout_constraintBottom_toTopOf="@+id/inputUserPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<dk.eatmore.rns.myutils.PasswordView
android:id="@+id/inputUserPassword"
android:layout_width="0dp"
android:layout_height="@dimen/mediumheight"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:background="@drawable/edit_text_bg"
android:hint="@string/password"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="@color/text"
android:textColorHint="@color/text"
android:textSize="@dimen/login_text_size"
app:layout_constraintBottom_toTopOf="@+id/btnUserLogin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/btnUserLogin"
android:layout_width="match_parent"
android:layout_height="@dimen/mediumheight"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:background="@drawable/button_green"
android:gravity="center"
android:text="@string/Login"
android:textAllCaps="false"
android:textColor="#FFF"
android:textSize="@dimen/login_text_medium_size"
app:layout_constraintBottom_toTopOf="@+id/txtNewUser"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/txtForgotPassword"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="32dp"
android:layout_marginStart="32dp"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="right"
android:text="@string/ForgotPassword"
android:textColor="@color/white"
android:textSize="@dimen/login_text_size"
app:layout_constraintBottom_toTopOf="@+id/viewRight"
app:layout_constraintEnd_toEndOf="@+id/btnUserLogin"
app:layout_constraintStart_toStartOf="@+id/guideline_ver" />
<TextView
android:id="@+id/txtNewUser"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:background="?attr/selectableItemBackground"
android:gravity="left"
android:text="@string/NewUser"
android:textColor="@color/green"
android:textSize="@dimen/login_text_size"
app:layout_constraintBottom_toTopOf="@+id/viewLeft"
app:layout_constraintEnd_toStartOf="@+id/guideline_ver"
app:layout_constraintStart_toStartOf="@+id/btnUserLogin" />
<TextView
android:id="@+id/txtOR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:gravity="center|start"
android:text="@string/or"
android:textColor="@color/white"
android:textSize="@dimen/login_text_medium_size"
app:layout_constraintBottom_toTopOf="@+id/facebookUserLogin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<View
android:id="@+id/viewLeft"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:alpha="0.9"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/txtOR"
app:layout_constraintEnd_toStartOf="@+id/txtOR"
app:layout_constraintStart_toStartOf="@+id/txtNewUser"
app:layout_constraintTop_toTopOf="@+id/txtOR">
</View>
<View
android:id="@+id/viewRight"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:alpha="0.9"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/txtOR"
app:layout_constraintEnd_toEndOf="@+id/txtForgotPassword"
app:layout_constraintStart_toEndOf="@+id/txtOR"
app:layout_constraintTop_toTopOf="@+id/txtOR">
</View>
<com.facebook.login.widget.LoginButton
android:id="@+id/login_buttonUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<Button
android:id="@+id/facebookUserLogin"
android:layout_width="0dp"
android:layout_height="@dimen/mediumheight"
android:layout_marginBottom="24dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:background="@drawable/button_blue"
android:drawableLeft="@drawable/fb"
android:paddingLeft="6dp"
android:text="@string/facebooklogin"
android:textAllCaps="false"
android:textColor="#FFF"
android:textSize="@dimen/login_text_medium_size"
app:layout_constraintBottom_toTopOf="@+id/shimmer_tv"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.romainpiel.shimmer.ShimmerTextView
android:id="@+id/shimmer_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="@string/swipe_for_menu"
android:textColor="@color/white"
android:textSize="@dimen/large"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:reflectionColor="@color/black" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
请在您添加片段代码的MainActivity中添加AdjustPan或AdjustResize。键盘会自动调整屏幕。