android - 如何在 DrawerLayout 内构建滑动 CardView?
问题描述
我正在努力创造CardView
可水平滑动的东西。
几天来,我一直在互联网上搜索并在 YouTube 上观看教程。在尝试了这些可能的解决方案和建议后,我的应用程序要么出现我无法解决的错误,要么崩溃。
所以,这是我的应用程序的屏幕截图。两个白色空格是CardView
我正在处理的。
我的目标类似于 Google Play 商店中的滑动卡片:
这是我的一部分activity_main.xml
:
<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:fitsSystemWindows="true"
tools:context=".MainActivity"
tools:openDrawer="start">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/jdCampusText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="JD Campus"
android:textSize="26sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/jdCampusCard"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.332" />
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/jdCampusCard"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
card_view:cardCornerRadius="4dp"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent">
</android.support.v7.widget.CardView>
<TextView
android:id="@+id/bsCampusText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="BS Campus"
android:textSize="26sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/bsCampusCard"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.657" />
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/bsCampusCard"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
card_view:cardCornerRadius="4dp"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintHorizontal_bias="0.0"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
card_view:layout_constraintVertical_bias="0.884">
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.DrawerLayout>
它不需要是CardView
,任何可滑动的,可以onClick
是对我来说都很好。
解决方案
推荐阅读
- cmake - add_custom_command POST_BUILD 在构建 3 个目标后运行 shell 脚本?
- javascript - 如何在将 HTML div 拖动到另一个位置时显示隐藏的 div
- openpyxl - openpyxl:chart.title =“图表标题”不起作用。如何将标题添加到散点图?
- r - R - 当两列或多列连续匹配时,在数据框中创建新列
- python - 通过矩阵查找所有路线
- php - 从 url 路径中获取最后 3 个单词
- gradle - Kotlin 依赖项的行为不像 Kotlin
- json - 如何在 Haxe 中将 JSON/动态结构转换为地图?
- javascript - querySelector 不返回 iframe 内的类元素
- node.js - 使用 Firebase CLI 尝试部署时出现 NPM 错误