Android ScrollView:底部按钮未显示
Android ScrollView: Bottom Button not showing
问题是我想让我的注册 activity 可滚动,但是每当我启动该应用程序时,我都可以滚动但无法查看下面的按钮。我试过将 alignParentTop = true 放在第一个 edittext 上。
这是我的代码:
<LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<!-- Add CONi icon here -->
<EditText
android:id="@+id/editlastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="@string/lastname"
android:inputType="textPersonName" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical">
<Button
android:id="@+id/btn_signup"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/round"
android:text="@string/signup"
android:textColor="@color/color3"
android:layout_marginBottom="20dp"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Use This XML Code
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<!-- Add CONi icon here -->
<EditText
android:id="@+id/editlastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<Button
android:id="@+id/btn_signup"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="signup"
android:layout_marginBottom="20dp"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
我对这个常见问题的解决方案是给最后一个 view/widget 一个“底边距”,如果问题仍然存在,请也添加一个 marginTop 值。
这对我有用,希望对你也有用!
问题是我想让我的注册 activity 可滚动,但是每当我启动该应用程序时,我都可以滚动但无法查看下面的按钮。我试过将 alignParentTop = true 放在第一个 edittext 上。
这是我的代码:
<LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<!-- Add CONi icon here -->
<EditText
android:id="@+id/editlastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="@string/lastname"
android:inputType="textPersonName" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical">
<Button
android:id="@+id/btn_signup"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/round"
android:text="@string/signup"
android:textColor="@color/color3"
android:layout_marginBottom="20dp"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Use This XML Code
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<!-- Add CONi icon here -->
<EditText
android:id="@+id/editlastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:ems="10"
android:hint="lastName"
android:inputType="textPersonName" />
<Button
android:id="@+id/btn_signup"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="signup"
android:layout_marginBottom="20dp"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
我对这个常见问题的解决方案是给最后一个 view/widget 一个“底边距”,如果问题仍然存在,请也添加一个 marginTop 值。 这对我有用,希望对你也有用!