我正在使用约束布局帮助器流程来构建类似于计算器的用户界面。
我在定位由我的Flow对象引用的引用视图时遇到问题。
请参阅所附图片my flow layout pic
如您所见,我想将单个底部按钮移到布局顶部。如何使用Flow帮助器将其移动到布局的左侧或右侧。
这是创建我需要修改的布局的Flow帮助器对象的代码。
<androidx.constraintlayout.helper.widget.Flow
android:id="@+id/flow"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent = "0.8"
app:constraint_referenced_ids ="a,b,c,d,e"
android:background="@drawable/my_own_drawable"
android:padding="20dp"
app:flow_verticalGap = "10dp"
app:flow_horizontalGap = "10dp"
app:flow_maxElementsWrap = "2"
app:flow_wrapMode = "aligned"
app:flow_verticalAlign="top" // I Thought this line would do the job, but it did not
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mytextview"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
</androidx.constraintlayout.helper.widget.Flow>
将创建以下按钮:
<Button
android:id="@+id/e"
android:layout_width = "0dp"
android:layout_height = "0dp"
app:layout_constraintHorizontal_weight="1"
android:padding="20dp"
app:layout_constraintHeight_percent = "0.1"
android:text="17"
tools:ignore="MissingConstraints"
/>
<Button
android:id="@+id/no1"
android:layout_width="0dp"
android:layout_height = "0dp"
app:layout_constraintHeight_percent = "0.1"
app:layout_constraintHorizontal_weight="1"
android:background="@android:color/transparent"
android:enabled="false"
tools:ignore="MissingConstraints"
/>
注意,它们两个的水平权重相同= 1。另外,ID = no1的按钮仍然可见,但背景透明,并且已启用为false。因此,它不会被用户单击。
我们可以使用以下行将可见按钮(id = e)移动到布局的左侧或右侧在Flow帮助器对象中:
app:constraint_referenced_ids ="e,no1,a,b,c,d" //will move button( id = e) to left side
app:constraint_referenced_ids ="no1,e,a,b,c,d" //will move button( id = e) to right