对齐顶部的视图和底部的按钮

鲁斯塔姆·伊布拉吉莫夫

我需要实现以下视图

在此处输入图片说明

我尝试使用约束布局:

<android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toTopOf="@id/segmentedButton">
     </FrameLayout>

     <Buttons
                android:id="@+id/segmentedButton"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent">
     </Buttons>

</android.support.constraint.ConstraintLayout>

当有很多项目时效果很好,但是当只有 2-3 个时,它会在中间显示它们。另外,我尝试使用 LinearLayout 但没有运气。

乌麦尔

您也可以使用它RelativeLayout来获得所需的结果。通过使用以下代码,您可以将剩余 2 或 3 个项目显示在顶部。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<FrameLayout
    android:id="@+id/frameLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/segmentedButton"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true" />

<Button
    android:id="@+id/segmentedButton"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

</RelativeLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章