【发布时间】:2018-05-15 13:02:55
【问题描述】:
只要 CardView 的高度足够小,不需要滚动,我在 ScrollView 中有一个可以完美运行的 CardView。但是,如果 CardView 需要滚动(以显示更大的图像),则 CardView 的底部会被剪切。我究竟做错了什么?
这是我的 layout.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>
【问题讨论】:
-
用问题分享你的整个布局
-
我已经使用上面的代码测试了布局,省略了其他元素。结果(cardView 的底部被剪切)是一样的。
-
您是否尝试在您的
ScrollViewer中添加android:clipToPadding="false"和android:clipChildren="false" -
并且还使用
android:layout_height="match_parent"作为ScrollViewer -
设置
android:layout_height="wrap_content"和android:fillViewPort=true似乎有点奇怪。你想在那里实现什么目标?
标签: android xml android-layout scrollview android-cardview