2017-11-06 3 views
0

Ich habe ein Hauptlayout, in dem ich das Constraint-Layout als Include-Tag hinzufüge. Hier ist mein Hauptlayout.Wie kann man das Beschränkungslayout im Hauptlayout entsprechend einbeziehen?

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/text1" 
     android:textAlignment="center" 
     android:textColor="@color/app_theme_primary" 
     android:textSize="@dimen/large_header_text_size" /> 

    <TextView 
     android:id="@+id/version_number" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/version_number" 
     android:textAlignment="center" 
     android:textColor="@color/common_main_background" 
     android:textSize="@dimen/secondary_text_size"/> 

    <TextView 
     android:id="@+id/develop_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/padding_10dp" 
     android:gravity="center" 
     android:text="@string/developed_text" 
     android:textColor="@color/common_main_background" 
     android:textStyle="bold" /> 

    <include layout="@layout/common_layout"/> 

    <TextView 
     android:id="@+id/trademarks" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:text="@string/trademarks" 
     android:textAlignment="center" 
     android:paddingTop="@dimen/multi_screen_small_padding" 
     android:textColor="@color/common_main_background" 
     android:textSize="@dimen/secondary_text_size" /> 
    </LinearLayout> 

Meine Einschränkung Layout, das wie unten

von zwei imageViews besteht
<android.support.constraint.ConstraintLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/logo1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:contentDescription="@null" 
     android:paddingTop="@dimen/multi_screen_medium_padding" 
     android:paddingStart="@dimen/multi_screen_medium_padding" 
     android:paddingEnd="@dimen/multi_screen_medium_padding" 
     android:src="@drawable/logo1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="8dp" 
     android:layout_marginRight="16dp"/> 

    <ImageView 
     android:id="@+id/logo2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:contentDescription="@null" 
     android:src="@drawable/logo2" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/logo1" 
     android:layout_marginTop="8dp" 
     app:layout_constraintDimensionRatio="w,1:1"/> 

</android.support.constraint.ConstraintLayout> 

Meine Forderung sind
1.Constraint Layout richtig in Haupt-Layout ausgestattet werden sollte, aber hier habe ich vor Problem ist letzte Textview (id : Warenzeichen), die nicht auf dem Bildschirm angezeigt werden, da das Beschränkungslayout den Bildschirm bis zum unteren Rand des Bildschirms eingenommen hat.
2. Zweites Bild (logo2) sollte sich entsprechend der Bildschirmgröße anpassen (kleiner Bildschirm kleiner größerer Bildschirm etwas größer).

Bitte helfen Sie mir, wie es geht? Danke im Voraus.

+0

Sie müssen verschiedene Auflösungen des gleichen Bildes verwenden. Lesen Sie [this] (https://stackoverflow.com/questions/37207443/how-to-put-single-image-for-different-screen-size). – gbruscatto

+0

Sie sollten Strg + K oder Cmd + K verwenden, um die Quellcode-Chunks richtig zu formatieren. –

+0

Dies ist kompliziert. Also Beste Lösung wäre zu tun, was gbruscatto oder es prozentual zu tun: https://stackoverflow.com/questions/37318228/how-to-make-constraintlayout-work-with-percentage-values ​​ –

Antwort

0

Nach mehreren Stunden harte Arbeit, habe mich perfekte Antwort für meine Frage. Überprüfen Sie bitte unten
Mein main_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 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:fillViewport="true"> 

<android.support.constraint.ConstraintLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 


    <TextView 
     android:id="@+id/app_name" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@string/app_name" 
     android:textAlignment="center" 
     android:textColor="@color/theme_primary" 
     android:textSize="@dimen/large_header_text_size" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent"/> 

    <TextView 
     android:id="@+id/version_number" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="@string/version_number" 
     android:textAlignment="center" 
     android:textColor="@color/common_main_background" 
     android:textSize="@dimen/secondary_text_size" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/app_name"/> 

    <TextView 
     android:id="@+id/develop_text" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:paddingTop="@dimen/padding_10dp" 
     android:text="@string/developed_by" 
     android:textColor="@color/common_main_background" 
     android:textStyle="bold" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/version_number"/> 

    <include 
     android:id="@+id/common_layout" 
     layout="@layout/common_layout" 
     android:layout_width="0dp" 
     android:layout_height="324dp" 
     android:layout_marginTop="@dimen/multi_screen_medium_padding" 
     app:layout_constraintBottom_toTopOf="@+id/trademarks" 
     app:layout_constraintDimensionRatio="1:0.90" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/develop_text"/> 

    <TextView 
     android:id="@+id/trademarks" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="@dimen/multi_screen_medium_padding" 
     android:text="@string/trademarks" 
     android:textAlignment="center" 
     android:textColor="@color/common_main_background" 
     android:textSize="@dimen/secondary_text_size" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/common_layout"/> 

</android.support.constraint.ConstraintLayout> 
</ScrollView> 

Meine umfassen xml (secondary_layout.xml)

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/main_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ImageView 
    android:id="@+id/logos" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    android:contentDescription="@null" 
    android:src="@drawable/logos" 
    app:layout_constraintBottom_toTopOf="@+id/alliance" 
    app:layout_constraintHorizontal_bias="0.5" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginLeft="@dimen/multi_screen_medium_padding" 
    android:layout_marginRight="@dimen/multi_screen_medium_padding" 
    android:layout_marginTop="@dimen/multi_screen_medium_padding" 
    android:layout_marginBottom="@dimen/multi_screen_medium_padding"/> 

<ImageView 
    android:id="@+id/alliance" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_marginLeft="0dp" 
    android:layout_marginRight="0dp" 
    android:layout_marginStart="8dp" 
    android:layout_marginTop="@dimen/multi_screen_medium_padding" 
    android:contentDescription="@null" 
    android:src="@drawable/alliance" 
    app:layout_constraintBottom_toBottomOf="@+id/main_layout" 
    app:layout_constraintDimensionRatio="3:1" 
    app:layout_constraintHorizontal_bias="0.50" 
    app:layout_constraintLeft_toLeftOf="@+id/logos" 
    app:layout_constraintRight_toRightOf="@+id/logos" 
    app:layout_constraintTop_toBottomOf="@+id/logos" 
    app:layout_constraintVertical_bias="0.50"/> 
</android.support.constraint.ConstraintLayout> 

Vielen Dank für Anregungen.

0

Der Titel passt nicht die Frage gut, aber hier einige Tipps und eine Lösung:

1- Sie sind auf der logo2

2- Auch die Einschränkung auf den Grund der übergeordneten Ansicht fehlt Verpackung Inhalt und geben 1,1 ist keine gute Idee

Lösung: Constraint die Ansicht nach unten dann Platz 0DP für die Höhe.

<android.support.constraint.ConstraintLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/logo1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:contentDescription="@null" 
     android:paddingTop="@dimen/multi_screen_medium_padding" 
     android:paddingStart="@dimen/multi_screen_medium_padding" 
     android:paddingEnd="@dimen/multi_screen_medium_padding" 
     android:src="@drawable/logo1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="8dp" 
     android:layout_marginRight="16dp" /> 

    <ImageView 
     android:id="@+id/logo2" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginTop="8dp" 
     android:contentDescription="@null" 
     android:src="@drawable/logo1" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintDimensionRatio="w,1:1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/logo1" /> 

</android.support.constraint.ConstraintLayout> 
+0

Danke für schnelle Antwort, aber wenn mir das Logo gefällt2 wird zu groß. – kodali

+0

Hi Mohammad, ich habe meine Frage und den Code ebenfalls bearbeitet, bitte überprüfe und kannst du irgendeinen Vorschlag machen? Bitte lassen Sie mich wissen, wenn Sie eine Klärung benötigen. – kodali

+0

Sie sollten Strg + K oder Cmd + K verwenden, um Ihre Quellcode-Chunks richtig zu formatieren. –

0

Verwenden Sie die ScaleType-Eigenschaft von ImageView. Es hat all diese Eigenschaften:

CENTER - Center das Bild, aber skaliert nicht das Bild.

CENTER_CROP - Skalieren Sie das Bild gleichmäßig.

CENTER_INSIDE - Zentrieren Sie das Bild innerhalb des Containers, anstatt die Kante exakt anzupassen.

FIT_CENTER - Skalieren Sie das Bild von der Mitte.

FIT_END - Skalieren Sie das Bild vom Ende des Containers.

FIT_START - Skalieren Sie das Bild vom Anfang des Containers.

FIT_XY - Füllen Sie das Bild aus den X- und Y-Koordinaten des Containers.

MATRIX - Skalieren Sie mit der Bildmatrix beim Zeichnen. Beispiel:

android:scaleType="center" 

Schauen Sie sich diese Dokumentation Click here

+0

Wenn ich scaleType verwende, wird das Seitenverhältnis verlieren, habe ich recht? – kodali

+0

ja und nein. Sie sehen, dass es mehrere Werte für scaleType gibt, wie Sie sehen, im Falle von centre zeigt es das gesamte Bild an, egal welche Auflösung Sie haben, aber es wird sehr viel Platz einnehmen, wenn Ihr Bild groß ist. Aber wenn Sie center_crop verwenden, können Sie das Bild auch skalieren. U wird etwas Seitenverhältnis verlieren, aber es wird versuchen, es gleichmäßig einzustellen. Wie auch immer, es funktioniert. Ich benutze center_crop für mein Bild die ganze Zeit. Versuche mit verschiedenen Werten zu experimentieren. Sehen Sie, welcher Ihrer Anforderungen entspricht –

Verwandte Themen