2017-09-21 8 views
4

以下のビューは正方形である必要があります。私はまた、一定の大きさに制限されたビューを望んでいます。何らかの理由で、ConstraintLayoutは、同じ要素のdimensionRatioと組み合わせて使用​​すると、max width/heightプロパティを無視しています。ConstraintLayoutはDimensionRatioと組み合わせて最大幅/高さを考慮しません

<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"> 
    <View 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     app:layout_constraintTop_toTopOf="@+id/guideline_top" 
     app:layout_constraintDimensionRatio="1:1" 
     app:layout_constraintLeft_toLeftOf="@+id/guideline_left" 
     app:layout_constraintRight_toRightOf="@+id/guideline_right" 
     app:layout_constraintBottom_toBottomOf="@+id/guideline_bottom" 
     app:layout_constraintWidth_max="100dp" 
     app:layout_constraintHeight_max="100dp"/> 

現時点では、次のようにビューをコンテナに入れて回避策を使用しています。しかし、私はむしろ私のレイアウト階層を可能な限りフラットにしておきたいと思います。

<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"> 
    <android.support.constraint.ConstraintLayout 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      app:layout_constraintTop_toTopOf="@+id/guideline_top" 
      app:layout_constraintLeft_toLeftOf="@+id/guideline_left" 
      app:layout_constraintRight_toRightOf="@+id/guideline_right" 
      app:layout_constraintBottom_toBottomOf="@+id/guideline_bottom" 
      app:layout_constraintWidth_max="100dp" 
      app:layout_constraintHeight_max="100dp"> 
      <View 
       android:layout_width="0dp" 
       android:layout_height="0dp" 
       app:layout_constraintTop_toTopOf="parent" 
       app:layout_constraintDimensionRatio="1:1" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintBottom_toBottomOf="parent" 
       /> 

これは制約のレイアウトで、最大幅と高さを寸法比と組み合わせて使用​​できないという制約ですか?

私はConstraintLayout v1.0.2を使用しています。

答えて

4

これはConstraintLayoutは、あなたの最大の幅と高さを拾う起こすべきで

`app:layout_constraintDimensionRatio="H,1:1"` 

または

`app:layout_constraintDimensionRatio="W,1:1"` 

のいずれかを指定します。ドキュメントの"Ratios"を参照してください。

+0

私のために働いた!ありがとう:) – Jono0

関連する問題