Android 利用ConstraintLayout約束banner 比例顯示

<android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <com.youth.banner.Banner
                        android:layout_width="match_parent"
                        android:id="@+id/banner"
                        app:layout_constraintDimensionRatio="h,16:9"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        android:layout_height="0dp">

                    </com.youth.banner.Banner>
                </android.support.constraint.ConstraintLayout>

因爲初次接觸使用此View ,其中layout_constraintDimensionRatio 說明約束的比例 ,參數 h,16:9,意思是約束高,按照寬的9/16顯示。h和w之間的關係:h = w * ratio;需要注意的是約束寬或高,只需要,設置寬或高爲 0dp,設置match_parent不會起到作用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章