NestedScrollView 内的 CardView 在底部显示额外的 space
CardView inside NestedScrollView shows extra space in bottom
我的布局有问题。我将 cardView 放在 NestedScrollView 中,并且完全放在 CoordinatorLayout 中。而且,它在底部添加了很多填充物。有人可以解释为什么会这样吗?我知道 cardView 在低于 L 的设备中使用额外的填充来显示圆角和阴影,但它是否需要这么多的填充并且只在底部。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.startup.practice.getplaced.activities.InfoEventDetails">
<android.support.design.widget.AppBarLayout
android:id="@+id/info_event_details_appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/content_image_height"
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/info_event_details_collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp">
<ImageView
android:src="@drawable/manhattan_college_logo"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/sheet_text_scrim_height_top"
android:background="@drawable/scrim_top"
app:layout_collapseMode="pin"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/sheet_text_scrim_height_bottom"
android:layout_gravity="bottom"
android:layout_alignBottom="@+id/image"
android:background="@drawable/scrim_bottom"/>
<android.support.v7.widget.Toolbar
android:id="@+id/info_event_details_appbar_toolbar"
app:layout_collapseMode="pin"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/info_event_details_date"
android:text="12th July"
android:layout_alignParentRight="true"
android:textSize="@dimen/date_text_size"
android:textColor="#90000000"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/info_event_details_title"
android:layout_toLeftOf="@id/info_event_details_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Attention! Students placed in Amazon."
android:textColor="#ab000000"
android:textSize="@dimen/title_text_size"/>
<View
android:id="@+id/info_event_details_divider_title_content"
android:layout_below="@id/info_event_details_title"
style="@style/Divider"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
/>
<TextView
android:id="@+id/info_event_details_desc"
android:layout_below="@id/info_event_details_divider_title_content"
android:textSize="@dimen/content_text_size"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
曾经有过同样的问题,我通过将 CardView
包装在 FrameLayout
中来解决它
<android.support.v4.widget.NestedScrollView>
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/info_event_details_date"
android:text="12th July"
android:layout_alignParentRight="true"
android:textSize="@dimen/date_text_size"
android:textColor="#90000000"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/info_event_details_title"
android:layout_toLeftOf="@id/info_event_details_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Attention! Students placed in Amazon."
android:textColor="#ab000000"
android:textSize="@dimen/title_text_size"/>
<View
android:id="@+id/info_event_details_divider_title_content"
android:layout_below="@id/info_event_details_title"
style="@style/Divider"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
/>
<TextView
android:id="@+id/info_event_details_desc"
android:layout_below="@id/info_event_details_divider_title_content"
android:textSize="@dimen/content_text_size"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
我的布局有问题。我将 cardView 放在 NestedScrollView 中,并且完全放在 CoordinatorLayout 中。而且,它在底部添加了很多填充物。有人可以解释为什么会这样吗?我知道 cardView 在低于 L 的设备中使用额外的填充来显示圆角和阴影,但它是否需要这么多的填充并且只在底部。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.startup.practice.getplaced.activities.InfoEventDetails">
<android.support.design.widget.AppBarLayout
android:id="@+id/info_event_details_appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/content_image_height"
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/info_event_details_collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp">
<ImageView
android:src="@drawable/manhattan_college_logo"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/sheet_text_scrim_height_top"
android:background="@drawable/scrim_top"
app:layout_collapseMode="pin"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/sheet_text_scrim_height_bottom"
android:layout_gravity="bottom"
android:layout_alignBottom="@+id/image"
android:background="@drawable/scrim_bottom"/>
<android.support.v7.widget.Toolbar
android:id="@+id/info_event_details_appbar_toolbar"
app:layout_collapseMode="pin"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/info_event_details_date"
android:text="12th July"
android:layout_alignParentRight="true"
android:textSize="@dimen/date_text_size"
android:textColor="#90000000"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/info_event_details_title"
android:layout_toLeftOf="@id/info_event_details_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Attention! Students placed in Amazon."
android:textColor="#ab000000"
android:textSize="@dimen/title_text_size"/>
<View
android:id="@+id/info_event_details_divider_title_content"
android:layout_below="@id/info_event_details_title"
style="@style/Divider"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
/>
<TextView
android:id="@+id/info_event_details_desc"
android:layout_below="@id/info_event_details_divider_title_content"
android:textSize="@dimen/content_text_size"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
曾经有过同样的问题,我通过将 CardView
包装在 FrameLayout
<android.support.v4.widget.NestedScrollView>
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/info_event_details_date"
android:text="12th July"
android:layout_alignParentRight="true"
android:textSize="@dimen/date_text_size"
android:textColor="#90000000"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/info_event_details_title"
android:layout_toLeftOf="@id/info_event_details_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Attention! Students placed in Amazon."
android:textColor="#ab000000"
android:textSize="@dimen/title_text_size"/>
<View
android:id="@+id/info_event_details_divider_title_content"
android:layout_below="@id/info_event_details_title"
style="@style/Divider"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
/>
<TextView
android:id="@+id/info_event_details_desc"
android:layout_below="@id/info_event_details_divider_title_content"
android:textSize="@dimen/content_text_size"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
</android.support.v4.widget.NestedScrollView>