Android cardView中的浮动操作按钮位置
在XML设计中,我将浮动按钮设置在右上角,但当我将应用程序运行到设备中时,浮动按钮的位置不正确。 我将在我的设备中获得与XML设计相同的位置 我的XML设计: 设备显示:Android cardView中的浮动操作按钮位置,android,material-design,floating-action-button,Android,Material Design,Floating Action Button,在XML设计中,我将浮动按钮设置在右上角,但当我将应用程序运行到设备中时,浮动按钮的位置不正确。 我将在我的设备中获得与XML设计相同的位置 我的XML设计: 设备显示: 使用布局_gravity=right | bottom和margin=“…”并在CardView中设置浮动操作按钮 `或者在viewPager中设置,为什么不将框架布局更改为相对布局,我发现更好地使用布局更容易,从那里可以添加类似layout_Upper=“@id/imageprodcard”和layout_alignpa
使用
布局_gravity=right | bottom
和margin=“…”
并在CardView中设置浮动操作按钮
`或者在viewPager中设置,为什么不将框架布局更改为相对布局,我发现更好地使用布局更容易,从那里可以添加类似layout_Upper=“@id/imageprodcard”和layout_alignparentRight和TOP的内容。希望有帮助 离题-我不确定您的整个应用程序看起来是什么样子,但从您提供的示例来看,似乎您在每个CardView
上都放置了一个FAB
,根据这一做法,这是一个糟糕的做法。将FAB放在CardView中,或者在CardView中放置一个按钮,FAB是一个坏主意,或者,如果要在回收器视图中显示卡片视图,最好设置一个按钮
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="true"
android:layout_margin="4dp"
card_view:cardCornerRadius="7dp"
android:elevation="8dp"
app:cardPreventCornerOverlap="false"
>
<LinearLayout
android:orientation="vertical" android:layout_width="152dp"
android:layout_height="match_parent"
android:weightSum="1"
android:descendantFocusability="blocksDescendants">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/draw_menu"
android:id="@+id/imageprodcard" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/likeButtoncard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:clickable="true"
android:src="@drawable/heart"
android:layout_gravity="right"
app:borderWidth="0dp"
app:fabSize="mini"
app:layout_anchor="@id/imageprodcard"
app:backgroundTint="#FFCCBC"
app:srcCompat="@drawable/ic_favorite_border_black_24dps"
/>
</FrameLayout>
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="25dp"
android:id="@+id/nomprodtestcard"
android:textAllCaps="false"
android:fontFamily="casual"
android:textAlignment="center"
android:paddingLeft="5dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="16dp">
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="TextView"
android:layout_width="105dp"
android:layout_height="20dp"
android:id="@+id/prixprodtestcard"
android:textColor="@android:color/holo_red_light"
android:textAlignment="center"
android:paddingLeft="5dp"
android:elevation="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/rating"
android:layout_weight="777.07" />
<ImageView
android:layout_width="20dp"
android:layout_height="match_parent"
app:srcCompat="@android:drawable/btn_star"
android:id="@+id/imageView4"
android:scaleType="fitStart" />
</LinearLayout>
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="20dp"
android:id="@+id/qtestockcard"
android:textStyle="normal|italic"
android:textAlignment="center"
android:paddingLeft="5dp" />
</LinearLayout>
</android.support.v7.widget.CardView>