简体   繁体   中英

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. 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. 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. If the height is less than windowHeight - (minHeight1 + minHeight2) the linear layout does fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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