xml 布局:滚动视图剪切嵌入的 CardView 项目的底部



我在ScrollView中有一个CardView,只要CardView的高度足够小,不需要滚动,它就可以完美地工作。但是,如果 CardView 需要滚动(为了显示更大的图像(,则 CardView 的底部会被剪切。我做错了什么?

这是我的布局.xml文件的一部分:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:fillViewport="true" >
<android.support.v7.widget.CardView 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/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:elevation="8dp"
app:cardCornerRadius="8dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_yellow_lighten_4"
android:nestedScrollingEnabled="false"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView_downloaded"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:scaleType="fitCenter"
android:src="@android:drawable/ic_menu_gallery"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- several other TextView elements here not shown -->
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>

这是我找到的解决方案:

<android.support.v7.widget.CardView 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/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="8dp"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
>
  1. 从卡片视图中删除android:layout_margin="8dp"

  2. app:card_view:cardUseCompatPadding="true"添加到卡片视图

最新更新