[英]How does layout_width/height work together with min/max width/height
我試圖了解在 xml 中設置以下屬性時誰“獲勝”: 1. layout_width vs minWidth/maxWidth 2. layout_height vs minHeight/maxHeight
例如,以下代碼:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/pb_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/semi_transparent_black_for_pb_loader"
android:elevation="20dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ProgressBar
android:id="@+id/pb_loading"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
我想了解ProgressBar 的大小。 另外我發現了style="?android:attr/progressBarStyle" 的值。 附在這里:
<style name="Widget.ProgressBar">
<item name="indeterminateOnly">true</item>
<item name="indeterminateDrawable">@drawable/progress_medium_white</item>
<item name="indeterminateBehavior">repeat</item>
<item name="indeterminateDuration">3500</item>
<item name="minWidth">48dip</item>
<item name="maxWidth">48dip</item>
<item name="minHeight">48dip</item>
<item name="maxHeight">48dip</item>
<item name="mirrorForRtl">false</item>
</style>
現在,有人可以告訴我使用WRAP_CONTENT它的時候為什么似乎大小是根據為minWidth,maxWidth,了minHeight,maxHeight,確定而設定進度的layout_width和layout_height為“0dp”,那么它的“戰勝”過分鍾時/ max 並且在屏幕上占據了很多位置?
當您將 layout_width 和 layout_height 設置為“0dp”時,它將遵守定義的約束。 在你的情況下:
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
所以它將占用父布局的整個空間。 這類似於“match_parent”。
在這種情況下,“wrap_content”的默認大小為您在樣式定義中找到的 48dp。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.