我用constraintLayout和layout_constraintDimensionRatio = 「1:1」 (寬度warp_content,高度是0dp(match_constraint))ConstraintLayout layout_constraintDimensionRatio不工作
結果,我期望的寬度和高度爲1:1,但不工作。
出了什麼問題?
我附上了代碼和截圖。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@android:color/holo_blue_bright"
android:gravity="center"
android:text="Hello World!11"
app:layout_constraintDimensionRatio="1:1" />
</android.support.constraint.ConstraintLayout>
我引述有關Constraintlayout Android開發者網站。 https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html#DimensionConstraints
「比:: 您還可以定義一個小部件的一個尺寸爲另一種的比例。爲了做到這一點,你需要至少有一個約束的尺寸設置爲0dp(即MATCH_CONSTRAINT),並且屬性layout_constraintDimentionRatio設置成給定的比例,例如:
<Button android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1" />
將設置按鈕的高度是相同的作爲其寬度「。
- >但我沒有工作。
ConstrainLayout的版本是什麼? – Shailesh
嗨Shailesh。我用1.0.2 – pistolcaffe
'match_parent'不支持。你需要設置'0dp',以便'ConstraintLayout'相應地設置它。檢查這個http://stackoverflow.com/questions/37603751/set-width-to-match-constraints-in-constraintlayout?rq=1 – Shailesh