本文介绍了将浮动按钮固定在cardview上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将浮动按钮锚定在cardview上,但是没有成功.
I try to anchor an floating button on a cardview without success.
<?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:orientation="vertical">
<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:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:background="@android:color/white"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
..... my view ...
</android.support.v7.widget.CardView>
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@id/card_view"
app:layout_anchorGravity="bottom|end|right"
android:layout_margin="16dp"
android:clickable="true"/>
</LinearLayout>
结果是这样的:
我希望浮动按钮显示为绿色圆圈.此布局用于RecyclerView
I want that floating button appear like the green circle.This layout is used in RecyclerView
这是实现这一目标的一种方法吗?
Is it a way to achieve this ?
推荐答案
能否在下面的代码中添加浮动按钮
Can you add below code your floating button
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="297dp"
android:id="@+id/relativeLayout">
<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:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:background="@android:color/white"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
..... my view ...
</android.support.v7.widget.CardView>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:srcCompat="@android:drawable/ic_dialog_email"
android:layout_marginRight="12dp"
android:layout_marginEnd="12dp"
android:layout_marginTop="165dp"
android:layout_alignTop="@+id/relativeLayout"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
这篇关于将浮动按钮固定在cardview上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!