【发布时间】:2015-10-09 06:38:20
【问题描述】:
我创建了一个 ListView,并在其中添加了 CardView。
如图所示,当我开始滚动时,ListView 中的最后一个 Card 没有完全显示。它会向上滚动,但不会出现在底部的 Android 导航栏上方。我一直在 HTC One M8 上进行测试。
这是列表视图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@+id/wanna_list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:divider="@null"/>
</LinearLayout>
这是我膨胀并设置到列表视图适配器中的 CardView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/cv"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
card_view:cardCornerRadius="6dp"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="2dp">
<!-- compat padding is required if using AppCompat -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp" >
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/thumbnail"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp"
android:src="@drawable/india"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/firstLine"
android:layout_toRightOf="@+id/thumbnail"
android:layout_alignParentTop="false"
android:textSize="20sp"
android:text="Tennis with Peter"
android:layout_alignTop="@+id/thumbnail" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/secondLine"
android:layout_below="@+id/firstLine"
android:text="10 Oct at 7pm"
android:layout_alignLeft="@+id/firstLine" />
<Button
android:layout_width="180dp"
android:layout_height="wrap_content"
android:text="YES"
android:id="@+id/button3"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignLeft="@+id/thumbnail" />
<Button
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="NO"
android:id="@+id/button4"
android:layout_toRightOf="@+id/button3"
android:layout_alignBottom="@+id/button3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="false" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我也尝试了我的卡片视图布局,但没有将其包装在 LinearLayout 中,但它仍然无法正常工作。
布局 xml 中是否有一个设置可以解决这个问题?
提前致谢。
【问题讨论】:
-
在卡片视图的底部添加边距。
-
为
listview添加一些顶部和底部边距 -
这是标准的做法吗?似乎很奇怪,Android 无法识别其在列表中的剪辑部分。
标签: android android-layout listview android-listview android-cardview