ConstraintLayoutを使用して均等に5つの四角形を得るにはどうすればいいですか?フレキシブルサイズは画面の幅によって異なりますか?ConstraintLayout:均等に分散された正方形のビュー
-2
A
答えて
0
PRECENTAGEと
使用ガイドライン、このような何か:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="@+id/guideline"
app:layout_constraintGuide_begin="316dp"
android:orientation="horizontal" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/guideline2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.502" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="@+id/guideline2"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.2" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="@+id/guideline2"
app:layout_constraintRight_toLeftOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.502" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="@+id/guideline3"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.4" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline4"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.502" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="@+id/guideline4"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.6" />
<Button
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="@+id/guideline4"
app:layout_constraintRight_toLeftOf="@+id/guideline5"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintVertical_bias="0.503" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="@+id/guideline5"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.8" />
<Button
android:id="@+id/button6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="@+id/guideline5"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
右クリックConstraintLayout上/垂直/ Horisontalガイドラインを追加し、ガイドラインを追加するには... が、それはあなた
お役に立てば幸いです乾杯
0
親のすべての側面に接続されているウィジェットのチェーンを作成する必要がありますコンテナ(この親コンテナのディメンションを必要な/必要なものに設定します)。正方形のパターンを確保するには、各ウィジェットにapp: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:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/frame1"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/frame2"
app:layout_constraintTop_toTopOf="parent"
/>
<FrameLayout
android:id="@+id/frame2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/frame1"
app:layout_constraintRight_toLeftOf="@+id/frame3"
app:layout_constraintTop_toTopOf="parent"
/>
<FrameLayout
android:id="@+id/frame3"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/frame2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</android.support.constraint.ConstraintLayout>
-2
あなただけの最初のビューにビューに制約を追加する必要があります。上部と下部の両方に。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/uno"
android:layout_width="0dp"
android:layout_height="0dp"
app:cardBackgroundColor="@color/colorPrimary"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="@+id/dos"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="8dp"/>
<android.support.v7.widget.CardView
android:id="@+id/dos"
android:layout_width="0dp"
android:layout_height="0dp"
app:cardBackgroundColor="@color/colorPrimaryDark"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="@+id/tres"
app:layout_constraintStart_toEndOf="@+id/uno"
app:layout_constraintTop_toTopOf="@id/uno"
app:layout_constraintBottom_toBottomOf="@id/uno"/>
<android.support.v7.widget.CardView
android:id="@+id/tres"
android:layout_width="0dp"
android:layout_height="0dp"
app:cardBackgroundColor="@color/colorAccent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/dos"
app:layout_constraintTop_toTopOf="@id/uno"
app:layout_constraintBottom_toBottomOf="@id/uno" />
+0
私はこれを参照しています:app:layout_constraintTop_toTopOf = "@ id/uno" app:layout_constraintBottom_toBottomOf = "@ id/uno" – fer
関連する問題
- 1. 均等に分散違い
- 2. Android ConstraintLayout:3つのボタンが幅に均等に分散します
- 3. Cassandraデータが均等に分散されない
- 4. 弾性探査荷重が均等に分散されない
- 5. Solrのシャード分布データが均等に分散されていません
- 6. Android Constraintlayoutを使って均等に分散した四角い行を作成する
- 7. データを境界全体に均等に分散する方法
- 8. Excel - 均等に分散された列車とテストセットにデータを分割する方法
- 9. Seekbar - 点を均等に分散した画像を追加
- 10. ConstraintLayout - ボタン間の均等なスペース
- 11. レイアウト内のビューの均等分布
- 12. Amazon Titan:データがDynamoDBパーティションに不均等に分散されています
- 13. 小さいスペースの均等に分割されたdiv
- 14. 拡散画像はタブローに均等に表示されます
- 15. ジョブを均等に分散しないマルチプロセッシング - Python
- 16. Excel VBAで複数の列に均等に要素を均等に分散する
- 17. 私はVTKで均等に分散球(のpython)を作りたい
- 18. 9×3 rectを8等分の正方形に分割する
- 19. UUID分割を使用してディレクトリ内のファイルを均等に分散する
- 20. 均等配分アルゴリズム
- 21. numpyの/パンダの差分:均等に囲まれたナン要素
- 22. hdfs data skew、なぜファイルが均等に分散されていないのですか?
- 23. 協調的拡散マトリックスで香りを均等に分配する
- 24. グローバルに分散されたNeo4jのアーキテクチャ?
- 25. ハイブに均等に行を分散させる方法パフォーマンスを向上させるために、レデューサー間で別のテーブルのパーティションテーブルに上書きする方法
- 26. シングル関数のナンシー平均と分散?
- 27. JavaFXのGridPaneにスペースを均等に分散させることはできますか?
- 28. ウィンドウエディタタブの幅を均等に分散するように設定する方法は?
- 29. いくつかの行に均等に分割されたULを持たせる方法
- 30. 非等価サーバー上の分散コンピューティング
スタックオーバーフローへようこそ。あなたはすでにこれをやってみましたか? [良い質問をするにはどうすればいいですか](https://stackoverflow.com/help/how-to-ask)をご覧ください。スタックオーバーフローはコーディングサービスではありません。 ***あなたの問題を研究し、投稿する前に自分でコードを書いてみることをお勧めします***。 *特定の*に固執する場合は、[最小限の、完全で検証可能な例](https://stackoverflow.com/help/mcve)とあなたが試したことの概要を含めてお手伝いしてください。 – FluffyKitten