我有这样的文本视图
<androidx.constraintlayout.widget.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="wrap_content">
<TextView
android:id="@+id/textView_data_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:textColor="@color/grey_dark_top"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="data in here" />
</androidx.constraintlayout.widget.ConstraintLayout>
如您所见,我将顶部和底部边距设置为8 dp。但是我需要在满足特定条件时将顶部和底部约束更改为32 dp。所以我需要以编程方式进行更改该怎么做?
您可以使用LayoutParams: