Android の ConstraintLayout で特定ウィジェットの中心を軸に高さの異なるウィジェットを並列配置してみた件
5005 ワード
方法
ウィジェット A の中央を軸に配置したいウィジェット B にウィジェット A の ID を指定した layout_constraintTop_toTopOf
と layout_constraintBottom_toBottomOf
を設定します。
サンプル
ImageView の中心を軸にして TextView と Button を横並びに設置します。
コード
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round"
app:layout_constraintEnd_toStartOf="@id/text_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="フェアプレー・ポイントを差し上げます ⚽️"
android:textAppearance="?android:attr/textAppearanceMedium"
app:layout_constraintBottom_toBottomOf="@id/image_view"
app:layout_constraintEnd_toStartOf="@+id/button"
app:layout_constraintStart_toEndOf="@id/image_view"
app:layout_constraintTop_toTopOf="@id/image_view" />
<android.support.v7.widget.AppCompatButton
android:id="@id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="送信"
app:layout_constraintBottom_toBottomOf="@id/image_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/text_view"
app:layout_constraintTop_toTopOf="@id/image_view" />
</android.support.constraint.ConstraintLayout>
</layout>
結果
関連記事
Author And Source
この問題について(Android の ConstraintLayout で特定ウィジェットの中心を軸に高さの異なるウィジェットを並列配置してみた件), 我々は、より多くの情報をここで見つけました https://qiita.com/84d010m08/items/9797205ee453345e2e8d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .