繁体   English   中英

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

[英]Place dynamic view between two views vertically

这里是问题:我想放置一个具有动态高度的视图,该视图将在运行时根据两个视图之间的宽度(称为中心视图)进行计算。 棘手的部分是,顶视图和底视图的高度应适应中心视图的测量和布局后剩余的空间,并且其高度不应小于minHeight。 我设法将所有三个视图都放置在垂直线性布局中,顶部和底部的权重为1,中心视图的高度固定,但是当中心视图的高度大于某个值时,它将覆盖顶部和底部的视图及其minHeight参数被忽略。 这是布局的一部分,希望对您有所帮助:

<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>

通过将中心视图的高度限制为windowHeight-(minHeight1 + minHeight2)来解决该问题,因为minHeight1和minHeight2是已知常数。 如果高度小于windowHeight-(minHeight1 + minHeight2),则线性布局会很好

暂无
暂无

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

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