简体   繁体   English

android - 如何以编程方式从右到左设置浮动操作按钮重力

[英]android - how to set floating action button gravity from right to left programmatically

I have a floating action button.我有一个浮动操作按钮。 I want to change its gravity from right to left with help of my java code.我想借助我的 java 代码将其引力从右更改为左。

在此处输入图像描述

There is no any such methods to set the floating action button in left side. 没有任何此类方法可以在左侧设置浮动操作按钮。 You can look at the http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html 您可以查看http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html

If you are using RelativeLayout as parent you can set the gravity like this, 如果您将RelativeLayout用作父级,则可以这样设置引力,

android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_gravity="start|bottom"

如果您使用的是CoordinatorLayout,则可以这样设置重力,

app:layout_anchorGravity="top|start"

I met the problem like you.我遇到了像你这样的问题。 And I solved it using LayoutParams.我使用 LayoutParams 解决了它。 Here is the code.这是代码。

CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) this.mFab.getLayoutParams();
layoutParams.gravity = Gravity.START | Gravity.BOTTOM;
this.mFab.setLayoutParams(layoutParams);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:如何以编程方式设置浮动操作按钮的重力? - Android : How to set gravity of Floating Action Button Programmatically? 尽管设置了重力,Android Floating Action Button的位置仍然错误 - Android Floating Action Button wrong position despite gravity is set 如何在android中以编程方式向左或向右移动按钮 - how to move a button to left or right programmatically in android 浮动操作按钮重力不起作用 - Floating Action Button gravity not working Android:以编程方式设置的按钮重力不起作用 - Android : Button gravity set programmatically not working 如何在右下角显示浮动操作按钮-Android - How to display floating action button on bottom right corner - android 当我单击按钮时如何设置动画,在android中从左向右和从右向左移动图像? - How to set animation when I click on button at that time move image from left to right and right to left in android? 如何设置浮动操作按钮 - how to set the floating action button Material Design:如何为Android Floating Action Button设置透明度 - Material Design : how to set transparency for Android Floating Action Button 如何在浮动操作按钮的背景中设置图像而不是android中的颜色? - How to set Image in background of Floating action button instead of color in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM