【发布时间】:2020-01-05 08:15:23
【问题描述】:
我可以使用 fab 按钮制作卡片视图。我可以在卡片视图中锚定 fab 按钮,但在这里我想制作一个看起来像 BottomAppBar(材料设计)的卡片视图。
代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".fragments.ViewHistoryFragment"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
style="@style/Widget.MaterialComponents.BottomAppBar">
<!-- style="@style/Widget.MaterialComponents.BottomAppBar"-->
<com.google.android.material.card.MaterialCardView
android:id="@+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.CardView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#C3EFC2">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="sdfkjgasdfjasdf"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="sdfkjgasdfjasdf"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="sdfkjgasdfjasdf"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="sdfkjgasdfjasdf"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/cv"
android:src="@mipmap/ic_launcher"
android:layout_marginEnd="@dimen/margin8"
app:layout_anchorGravity="bottom|right|end"
app:borderWidth="@dimen/margin8"
app:backgroundTint="#343433" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我想喜欢这种类型的 这意味着我想要我的卡片视图中的摇篮直径。 attached my wanted output
任何人的任何建议都将受到赞赏。
【问题讨论】:
-
使用BottomAppBar
-
@GabrieleMariotti 也许如果我是对的,你不能使用 BottomApp Bar 代替卡片视图但是如果你认为可以,你可以给我一个例子。
-
这种方式用过,不知道能不能用。在任何情况下,您都必须将 MaterialShapeDrawable 也应用于 CardView。检查此链接:medium.com/ackee/…
-
@GabrieleMariotti 你给我投反对票了吗?我不这么认为,但也许你的链接对我有用。
-
绝对没有。这个问题很清楚也很有趣。
标签: android android-layout material-design android-cardview floating-action-button