Java 安卓系统中键盘弹出时如何滚动布局
我使用协调器布局制作了以下布局。但当键盘弹出时,一些元素会进入键盘下方,从而失去可见性。 所以,请帮助我解决这个问题。我已经尝试将adjustPan、adjustResize置于WindowsofInputMode下,但仍然不起作用。即使尝试使用嵌套的滚动视图,也没有成功Java 安卓系统中键盘弹出时如何滚动布局,java,android,scrollview,android-coordinatorlayout,Java,Android,Scrollview,Android Coordinatorlayout,我使用协调器布局制作了以下布局。但当键盘弹出时,一些元素会进入键盘下方,从而失去可见性。 所以,请帮助我解决这个问题。我已经尝试将adjustPan、adjustResize置于WindowsofInputMode下,但仍然不起作用。即使尝试使用嵌套的滚动视图,也没有成功 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/gradient"
android:gravity="center">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center|center_vertical"
android:background="@drawable/app_main_logo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="20dp"
android:text="My App"
android:textColor="#fff"
android:textSize="20dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.CardView
android:id="@+id/loginCardView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="250dp"
app:cardCornerRadius="10dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#fff">
<EditText
android:id="@+id/input_email_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="40dp"
android:hint="Username"
android:inputType="textEmailAddress"
android:textColor="#fff"
android:textColorHint="#fff" />
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#fff"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/input_password_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#fff"
android:textColorHint="#fff" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/capsule_button"
android:elevation="20dp"
android:gravity="center"
android:text="Sign In"
android:textColor="#fff"
android:textSize="20dp"
app:layout_anchor="@id/loginCardView"
app:layout_anchorGravity="bottom|center" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Don't have an account?" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="Create Now"
android:textStyle="bold" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
您可以使用Scrollview,它将启用滚动。所以你可以向上和向下滚动所有的布局。试试这个,如果你不想这样,你也可以检查正在折叠的工具栏。从这里
https://material.io/develop/android/components/collapsing-toolbar-layout/
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
//This is Scrollview you can adjust height and width as you want.
<ScrollView android:layout_marginTop="30dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/gradient"
android:gravity="center">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center|center_vertical"
android:background="@drawable/app_main_logo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="20dp"
android:text="My App"
android:textColor="#fff"
android:textSize="20dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.CardView
android:id="@+id/loginCardView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="250dp"
app:cardCornerRadius="10dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#fff">
<EditText
android:id="@+id/input_email_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="40dp"
android:hint="Username"
android:inputType="textEmailAddress"
android:textColor="#fff"
android:textColorHint="#fff" />
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#fff"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/input_password_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#fff"
android:textColorHint="#fff" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/capsule_button"
android:elevation="20dp"
android:gravity="center"
android:text="Sign In"
android:textColor="#fff"
android:textSize="20dp"
app:layout_anchor="@id/loginCardView"
app:layout_anchorGravity="bottom|center" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Don't have an account?" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="Create Now"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
//这是Scrollview,您可以根据需要调整高度和宽度。
使用卡片视图到上根目录,然后使用其中包含的任何其他布局 感谢您的回复,但这将不起作用,因为scrollview只能容纳一个孩子。