Platz jedes Ihrer ImageViews
in ihrem eigenen ConstraintLayout
. Die layout_width
und layout_height
der ImageViews
sollten wrap_content
sein. Die layout_width
und layout_height
ihres Elternteils ConstraintViews
sollten bzw. wrap_content
sein.
Anker links ConstraintView
nach oben und Beginn der Eltern und das Recht ConstraintView
an die Spitze und Ende mit layout_constraintTop_toTopOf
, layout_constraintStart_toStartOf
und layout_constraintEnd_toEndOf
.
Fügen Sie auch die Ränder zum übergeordneten ConstraintViews
mit layout_marginTop
und layout_marginLeft
für die linke; layout_marginTop
und layout_marginRight
für das Recht.
Als nächstes erstellen Sie eine vertical
Guideline
als Kind Ihres Fragments. Stellen Sie layout_constraintGuide_percent
auf 0.5
ein. Geben Sie ihm eine id
von @+id/guideline
.
Stellen Sie den linken ConstraintView's
layout_constraintRight_toLeftOf
zu @+id/guideline
und das Recht ConstraintView's
layout_constraintLeft_toRightOf
-@+id/guideline
auch.
Dies sollte die ImageViews
Größen nach unten skalieren, wenn das Fragment nicht so breit ist.
Wenn Sie es möchten, ein Mindestabstand zwischen den beiden Bildern sein, können Sie layout_marginRight
nach links ConstraintView
hinzufügen und layout_marginLeft
nach rechts ConstraintView
. Die Einstellung auf 2dp
würde eine minimale Lücke von 4dp
ergeben.
Hier ist eine Beispiel-Layout-Datei. Bearbeiten Sie den Behälter ConstraintLayout's
layout_width
, um zu sehen, sie in Aktion:
<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="100dp"
android:layout_height="300dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:background="#333333">
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline"
app:layout_constraintGuide_percent="0.5"
android:orientation="vertical"/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintRight_toLeftOf="@+id/guideline"
android:layout_marginRight="2dp"
android:background="#FF0000">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@mipmap/ic_launcher"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp"/>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
app:layout_constraintLeft_toRightOf="@+id/guideline"
android:layout_marginLeft="2dp"
android:background="#00FF00">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@mipmap/ic_launcher"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp"/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
Nizza Ansatz! Ich habe versucht, mein wirkliches Problem zu vereinfachen, also sagte ich, ich habe zwei Bilder, aber ich habe vier ... In einer Zeile und ich habe 4 Zeile ... So habe ich 16 Bilder. :) – Zoltan
(plötzlich Enter mein Kommentar geschrieben ...) Also, Ihre Lösung sieht gut aus, aber ich konnte nicht verwenden, um mein echtes Problem zu lösen ... :( Evenmore, erlebte ich ein seltsames Android Studio Problem: In Textmodus Ich schreibe 'match_parent' zu meinem Bild, dann klicke ich auf Design, dann zurück zu Text und das Studio ersetze es zu einem festen Wert!: O Warum? – Zoltan