如何拥有这样一个可滚动的浮动 Cardview?
How to have a scrollable floating Cardview like this?
有谁知道如何拥有这样的浮动 Cardview 吗?
http://chairnerd.seatgeek.com/images/autocomplete_checkout.gif
背景图像应该能够以编程方式更改,卡片视图应该可以滚动。第一个 Cardview 的位置应该在图像下方的某个位置。提前致谢!
我自己想出来了,我会 post 我的解决方案在这里,以防有人 运行 遇到同样的情况。
布局文件应该如下所示:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:background="@color/bgGrey">
<ImageView
android:layout_width="match_parent"
android:layout_height="125dp"
app:srcCompat="@drawable/soccer"
android:id="@+id/imageView"
android:scaleType="centerCrop"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="120dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="6dp">
编辑: 在 LinearLayout 中,应该添加类似占位符的内容。否则最后的部分内容将无法显示。所以我用了一个textview来做到这一点。
<TextView
android:layout_width="match_parent"
android:layout_height="120dp" />
注意:这里的高度要和LinearLayout中的marginTop一致
是的,它是直接在 ScrollView
上的 cardView,或者 ListView
只是带有具有背景透明度的项目布局。
scrollview/listview 放在 FrameLayout
或 RelativeLayout
上。要么顶部有一个 padding/margin,要么第一个元素是透明的 "stub"。
在下方(首先在父布局中声明)scrollview/listview 您可以放置图像或任何其他静态组件。
您可以在上面放置其他浮动组件(例如示例中的结账按钮)
有谁知道如何拥有这样的浮动 Cardview 吗? http://chairnerd.seatgeek.com/images/autocomplete_checkout.gif
背景图像应该能够以编程方式更改,卡片视图应该可以滚动。第一个 Cardview 的位置应该在图像下方的某个位置。提前致谢!
我自己想出来了,我会 post 我的解决方案在这里,以防有人 运行 遇到同样的情况。
布局文件应该如下所示:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:background="@color/bgGrey">
<ImageView
android:layout_width="match_parent"
android:layout_height="125dp"
app:srcCompat="@drawable/soccer"
android:id="@+id/imageView"
android:scaleType="centerCrop"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="120dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="6dp">
编辑: 在 LinearLayout 中,应该添加类似占位符的内容。否则最后的部分内容将无法显示。所以我用了一个textview来做到这一点。
<TextView
android:layout_width="match_parent"
android:layout_height="120dp" />
注意:这里的高度要和LinearLayout中的marginTop一致
是的,它是直接在 ScrollView
上的 cardView,或者 ListView
只是带有具有背景透明度的项目布局。
scrollview/listview 放在 FrameLayout
或 RelativeLayout
上。要么顶部有一个 padding/margin,要么第一个元素是透明的 "stub"。
在下方(首先在父布局中声明)scrollview/listview 您可以放置图像或任何其他静态组件。
您可以在上面放置其他浮动组件(例如示例中的结账按钮)