我在NestedScrollView中包含一个ConstraintLayout但我遇到了问题。 当布局包括其高度为父级的马赫时。它表示ConstraintLayout的底部直到最后一个子视图。
这是我的Constraintlayout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
android:background="@color/background_card"
android:layoutDirection="ltr">
<ss.com.bannerslider.views.BannerSlider
android:id="@+id/image_banner_slider"
android:layout_width="match_parent"
android:layout_height="250dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:defaultIndicators="circle"
app:interval="7000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:loopSlides="true"
tools:src="@drawable/horse_banner_1" />
<com.example.davod.a4nal.Custom.CustomFontTextView
android:id="@+id/txt_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:text="به چهارنعل خوش آمدید"
android:textColor="@color/text_title_color"
android:textSize="@dimen/standard_size_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image_banner_slider" />
<Button
android:id="@+id/btn_sell_horse"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="56dp"
android:background="@drawable/selector_button_login"
android:text="فروش اسب"
android:textSize="@dimen/standard_size_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btn_request_horse"
app:layout_constraintTop_toBottomOf="@+id/txt_welcome" />
<Button
android:id="@+id/btn_request_horse"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="96dp"
android:background="@drawable/selector_button_login"
android:text=" درخواست اسب"
android:textSize="@dimen/standard_size_title"
app:layout_constraintEnd_toStartOf="@+id/btn_sell_horse"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image_banner_slider" />
<Button
android:id="@+id/btn_sell_horse_object"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="@drawable/selector_button_login"
android:text="فروش تجهیزات"
android:textSize="@dimen/standard_size_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btn_request_horse_object"
app:layout_constraintTop_toBottomOf="@+id/btn_sell_horse" />
<Button
android:id="@+id/btn_request_horse_object"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="16dp"
android:background="@drawable/selector_button_login"
android:text="درخواست تجهیزات"
android:textSize="@dimen/standard_size_title"
app:layout_constraintEnd_toStartOf="@+id/btn_sell_horse_object"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_request_horse" />
<Button
android:id="@+id/btn_gravitation_horse"
android:layout_width="317dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:background="@drawable/selector_button_login"
android:text="کشش"
android:textSize="@dimen/standard_size_title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/btn_sell_horse_object"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/btn_request_horse_object"
app:layout_constraintTop_toBottomOf="@+id/btn_sell_horse_object"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
这是我的主要布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="rtl"
tools:context="com.example.davod.a4nal.Activity.MainActivity">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/Base.ThemeOverlay.AppCompat.Dark">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
<com.example.davod.a4nal.Custom.CustomFontTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:text="چهارنعل"
android:textColor="@color/title_of_toolbar"
android:textSize="@dimen/standard_size_title" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include
layout="@layout/activity_main_bottom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/float_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:layout_margin="12dp"
app:fabSize="normal"
app:srcCompat="@drawable/vc_add_black_24dp"
tools:ignore="VectorDrawableCompat" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layoutDirection="rtl"
app:headerLayout="@layout/navigation_header_layout"
app:menu="@menu/navigation_menu" />
</android.support.v4.widget.DrawerLayout>
你有解决方案吗?
我的ConstraintLayout与父级不匹配,布局高度是换行内容。
答案 0 :(得分:0)
尝试将此添加到Scrollview元素
android:fillViewport="true"
答案 1 :(得分:0)
尝试将其添加到布局中的NestedScrollView
android:layout_height="match_parent"
android:fillViewport="true"