java - ConstraintLayout layoutParams setMargin() notWorking
问题描述
我有一个浮动操作按钮,我想以编程方式更改其位置
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/expandViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:visibility="visible"
android:layout_marginStart="168dp"
app:layout_constraintStart_toStartOf="@+id/coordinatorLayout1"
app:layout_constraintTop_toTopOf="@+id/coordinatorLayout1"
app:srcCompat="@mipmap/ic_launcher_round" />
我使用以下代码以编程方式更改位置。
ConstraintLayout.LayoutParams layoutParams=new
ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT,ConstraintLayout.LayoutParams.WRAP_CONTENT);
int left,right,top,bottom;
left=(int)MainActivity.device_width/2;
right=0;
top=(int) MainActivity.device_height-200;
bottom=0;
layoutParams.rightMargin=right;
layoutParams.topMargin=20;
layoutParams.leftMargin=left;
layoutParams.bottomMargin=bottom;
layoutParams.bottomToBottom=R.id.fb1;
layoutParams.startToStart=R.id.fb1;
但是layoutParams.rightMargin
,layoutParams.topMargin
和似乎不起作用layoutParam.leftMargin
。layoutParams.bottomMargin
请建议我一个解决方案。
解决方案
推荐阅读
- angular - ngSelect 总是返回 undefined
- database-migration - Create.io 创建表时的列顺序
- r - 如何在 R 中创建具有指定列和行数的空数据框?
- file - 如何根据部分文件名使用 Google Script 自动移动 Google Drive 中的文件?
- reactjs - Rapid onChange 导致 OnClick 不注册
- inotify - inotifywait - 执行命令时暂停监控
- c# - 如何从供应商/产品 ID 获取 USB 驱动器的驱动器号?
- r - 使用向量而不是R中的正则表达式从字符串中删除多个单词
- java - 确定 JLabel 文本是否被截断?
- php - 如何在另一个页面上获取 div 项的数据属性