我有这个约束布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="Overdraw">
<FrameLayout
android:id="@+id/popover"
style="@style/popover_style"
android:layout_width="@dimen/width"
android:layout_height="0dp"
android:layout_marginBottom="@dimen/bottom_margin"
android:layout_marginLeft="@dimen/side_margin"
android:layout_marginRight="@dimen/side_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="0">
</FrameLayout>
</android.support.constraint.ConstraintLayout>
我想通过代码更改popover
视图的位置。
有时会水平居中。
有时需要调整其左页边距大小。
我已经尝试过这段代码,但是视图似乎总是水平居中。
我想念什么?
private void setupPopoverPosition() {
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(rootView);
int bottomMargin =
getContext()
.getResources()
//some code
constraintSet.applyTo(rootView);
ConstraintLayout.LayoutParams layoutParams =
(ConstraintLayout.LayoutParams) popover.getLayoutParams();
layoutParams.topMargin = topMargin;
layoutParams.bottomMargin = bottomMargin;
layoutParams.rightMargin = popoverEndMargin;
popover.setLayoutParams(layoutParams);
popover.setLayoutParams(layoutParams);
popover.requestLayout();
}