【问题标题】:Background not filling entire screen in scrollview android背景没有填充滚动视图android中的整个屏幕
【发布时间】:2017-08-25 07:26:20
【问题描述】:

我正在开发一个应用程序,我需要用背景填充整个屏幕,这个视图包含一个滚动视图。问题是背景没有覆盖整个屏幕,它在底部有一条白色条纹,如下图所示。

我已经尝试了许多 scaleType 选项,例如 fitXY、centerInside 等,但都没有成功。 我的 XML 在下面。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/signup_background" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="40dp">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/image_view_photo"
                android:layout_width="130dp"
                android:layout_height="130dp"
                android:layout_gravity="center"
                android:layout_marginBottom="25dp"
                android:src="@drawable/camera_icon" />

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/edit_text_name"
                style="@style/BaseEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/name_icon"
                android:hint="@string/field_name"
                android:inputType="textCapWords" />

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/edit_text_email"
                style="@style/BaseEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/email_icon"
                android:hint="@string/field_email"
                android:inputType="textEmailAddress" />

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/edit_text_password"
                style="@style/BaseEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/password_icon"
                android:hint="@string/field_password"
                android:inputType="textPassword" />

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/edit_text_confirm_password"
                style="@style/BaseEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="35dp"
                android:drawableLeft="@drawable/password_icon"
                android:hint="@string/field_confirm_password"
                android:inputType="textPassword" />

            <com.jacksonueda.reachalert.Utils.LoadingButton
                android:id="@+id/btn_signup"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:text="@string/action_sign_up" />
        </LinearLayout>
    </android.support.constraint.ConstraintLayout>
</ScrollView>

谁能帮帮我?谢谢。

【问题讨论】:

    标签: android xml background fullscreen


    【解决方案1】:

    我认为你必须为ConstraintLayout 提供背景,宽度为wrap_content。同时为 ScrollView 和 ConstraintLayout wrap_content 设置你的高度。

    【讨论】:

      【解决方案2】:

      在约束布局中你必须指定约束。您没有在 ImageView 中指定约束

      <ImageView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:adjustViewBounds="true"
                  android:scaleType="centerCrop"
                  android:src="@drawable/signup_background" />
      

      替换为

      <ImageView
                  android:layout_width="0dp"
                  android:layout_height="0dp"
                  android:adjustViewBounds="true"
                  android:scaleType="centerCrop"
                  android:src="@drawable/signup_background"
                  card_view:layout_constraintBottom_toBottomOf="parent"
                  card_view:layout_constraintLeft_toLeftOf="parent"
                  card_view:layout_constraintRight_toRightOf="parent"
                  card_view:layout_constraintTop_toTopOf="parent" />
      

      【讨论】:

        【解决方案3】:

        尝试在您的 xml 中使用 RelativeLayout 而不是 ConstraintLayout。相对布局最适合重叠 xml 的两个元素。

        【讨论】:

          【解决方案4】:

          我得到了答案,我需要做的就是将一个 RelativeLayout 作为 ScrollView 的父级,如下所示。

          <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
          
              <ScrollView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:fillViewport="true">
          
                  <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:background="@drawable/signup_background"
                      android:orientation="vertical"
                      android:padding="40dp">
          
                      ...
          
                  </LinearLayout>
              </ScrollView>
          </RelativeLayout>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2012-01-28
            • 2023-03-25
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-07-17
            • 2020-12-12
            相关资源
            最近更新 更多