简体   繁体   English

将动态视图垂直放置在两个视图之间

[英]Place dynamic view between two views vertically

Here is the problem: I want to place a view with dynamic height which will be calculated at runtime according to the width (lets call it center view) between two views. 这里是问题:我想放置一个具有动态高度的视图,该视图将在运行时根据两个视图之间的宽度(称为中心视图)进行计算。 The tricky part is that the top and bottom views should adapt their height to fit the space left after center view measurement and layout, and their height shouldn't be less that minHeight. 棘手的部分是,顶视图和底视图的高度应适应中心视图的测量和布局后剩余的空间,并且其高度不应小于minHeight。 I managed to put all three views in vertical linear layout, where top and bottom have weight = 1 and center view is some fixed height, but when the center view height is becomes bigger than some value it covers top and bottom views and their minHeight param is ignored. 我设法将所有三个视图都放置在垂直线性布局中,顶部和底部的权重为1,中心视图的高度固定,但是当中心视图的高度大于某个值时,它将覆盖顶部和底部的视图及其minHeight参数被忽略。 Here is the part of the layout, hope it helps: 这是布局的一部分,希望对您有所帮助:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/topLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:minHeight="84dp"
        android:orientation="horizontal" >
        <!-- some content here -->
    </LinearLayout>

    <View
        android:id="@+id/centerView"
        android:layout_width="match_parent"
        android:layout_height="300dp" />

    <LinearLayout
        android:id="@+id/BottomLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:minHeight="62dp"
        android:orientation="horizontal" >
        <!-- some content here -->
    </LinearLayout>

</LinearLayout>

Solved it by restricting height of the center view to windowHeight - (minHeight1 + minHeight2) as minHeight1 and minHeight2 are known constants. 通过将中心视图的高度限制为windowHeight-(minHeight1 + minHeight2)来解决该问题,因为minHeight1和minHeight2是已知常数。 If the height is less than windowHeight - (minHeight1 + minHeight2) the linear layout does fine 如果高度小于windowHeight-(minHeight1 + minHeight2),则线性布局会很好

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

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