[英]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.