简体   繁体   English

即使 layout_constraintHeight_max/min 设置为 200dp,高度也不正确

[英]height is incorrect even with layout_constraintHeight_max/min set to 200dp

Why doesn't Linear Layout maxHeight work? 为什么线性布局 maxHeight 不起作用? maxHeight does not work on RecyclerView maxHeight 不适用于 RecyclerView

Height of section2 becomes 0 as I followed the instructions from above post.按照上面帖子的说明,section2 的高度变为 0。

My View Requirement is to have a:我的观点要求是:

  • TopBar followed by TopBar 其次是
  • 3 sections 3个部分
  • Section1 wraps height followed by Section1 包装高度后跟
  • Section2 maxHeight to 200dp or take/fill available height (followed by Section3) Section2 maxHeight 到 200dp 或取/填充可用高度(后跟 Section3)
  • Section3 height 45dp and aligns to bottom and Section3 高度 45dp 并与底部对齐
  • All 3 sections must be visible.所有 3 个部分都必须可见。
  • This entire view should center_parent of rootView of the activity.整个视图应该是活动的 rootView 的 center_parent。

  • Section1 is correct第一节是正确的
  • Section3 is correct第3节是正确的
  • But section2 height becomes 0 and is not visible if I don't set the min constraint.但是如果我不设置最小约束,section2 高度变为 0 并且不可见。
  • If I set minHeight constraint for section2, section3 becomes invisible.如果我为 section2 设置 minHeight 约束,section3 将变得不可见。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root_home_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/purple"
    tools:context="mose.moseinc.com.Tymeit.Activities.Home.Activity">
    <RelativeLayout
        android:layout_centerInParent="true"
        android:layout_width="match_parent"
        android:background="@color/aqua_blue"
        android:layout_height="wrap_content">
        <mose.moseinc.com.Tymeit.Views.Home.TopBar
            android:id="@+id/top_bar_home_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </mose.moseinc.com.Tymeit.Views.Home.TopBar>
        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/mainView"
            android:layout_below="@+id/top_bar"
            android:orientation="vertical"
            android:layout_height="wrap_content"
            android:layout_width="match_parent">
            <CustomView1
                android:id="@+id/section1"
                android:layout_width="match_parent"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="0dp"
                android:background="@color/green_theme"
                app:tileHeight="40dp"
                android:layout_height="wrap_content" />
            <CustomView2
                android:id="@+id/section2"
                app:layout_constraintTop_toBottomOf="@+id/section1"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginBottom="50dp"
                android:layout_width="match_parent"
                app:layout_constraintHeight_default="wrap"
                app:layout_constraintHeight_max="200dp"
                android:layout_height="0dp">
            </CustomView2>
            <CustomView3
                android:id="@+id/bottomBar"
                app:layout_constraintBottom_toBottomOf="parent"
                android:layout_width="match_parent"
                android:layout_height="45dp">
            </CustomView3>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </RelativeLayout>
</RelativeLayout>

android:layout_height="0dp" and app:layout_constraintHeight_max="200dp" dont work together. android:layout_height="0dp"app:layout_constraintHeight_max="200dp"一起使用。 Layout_height will always take prio and set the height of CustomView2 to 0. Layout_height 将始终采用优先级并将 CustomView2 的高度设置为 0。

What you need is to set android:layout_height="parent" .您需要设置android:layout_height="parent" Then it will try to take all available space it can get on the screen, but not exceed 200dp.然后它会尝试占用屏幕上所有可用空间,但不会超过 200dp。

You set CustomView3 to visibility="gone" this does not match your requirement of visibility.您将 CustomView3 设置为visibility="gone"这不符合您的可见性要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM