2017-12-20 8 views
-1

Dies ist meine Layout-Datei.ConstraintLayout layout_constraintHorizontal_bias scheint nicht zu funktionieren

<?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:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <EditText 
     android:layout_width="150dp" 
     android:layout_height="50dp" 
     android:hint="please input test content" 
     android:inputType="phone" 
     android:textColorHint="@android:color/holo_red_light" 
     android:textSize="13sp" 
     app:layout_constraintBottom_toTopOf="parent" 
     app:layout_constraintRight_toLeftOf="parent" /> 
    <TextView 
     android:layout_width="80dp" 
     android:layout_height="50dp" 
     android:gravity="center" 
     android:text="Hello" 
     android:textColor="@android:color/black" 
     app:layout_constraintBottom_toTopOf="parent" 
     app:layout_constraintHorizontal_bias="0.5" /> 
</android.support.constraint.ConstraintLayout> 

Folgen Sie Bild ist Vorschauansicht.

enter image description here

Ich möchte Textview bewegen, um Eltern Blick auf center_horizontal, aber layout_constraintHorizontal_bias=0.5" scheint nicht zu funktionieren.

Wer hat Ideen für dieses Problem? Danke erstmal!

+0

Wie lautet Ihre erwartete Ausgabe? –

+0

@Nilu TextView zur Mitte verschieben Horizontal – Cyrus

+0

@Cyrus Möchten Sie dies nur durch ConstraintLayout erreichen? –

Antwort

1

Versuchen Sie, diese

<?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:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <EditText 
     android:id="@+id/editText2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:ems="10" 
     android:hint="please input test content" 
     android:inputType="phone" 
     android:textColorHint="@android:color/holo_red_light" 
     android:textSize="13sp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" /> 

    <TextView 
     android:layout_width="80dp" 
     android:layout_height="50dp" 
     android:gravity="center" 
     android:text="Hello" 
     android:textColor="@android:color/black" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="0.5" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

</android.support.constraint.ConstraintLayout> 

EDIT

bias Sie es jedem Elternteil gezwungen geben müssen zu verwenden.

enter image description here

+0

Danke für Ihre Antwort, könnte dieser Weg wrok. aber warum 'app: layout_constraintHorizontal_bias = 0.5' nicht funktioniert. – Cyrus

+0

@Cyrus ich denke, keine Notwendigkeit von 'layout_constraintHorizontal_bias 'überprüfen aktualisiert ans –

+0

@Cyrus müssen Sie nicht arbeiten, weil Sie es nicht zu einem Elternteil zu Textansicht –

1

Try this:

app:layout_constraintHorizontal_bias="0.5" funktioniert nicht, weil Sie es nicht alle Eltern gezwungen haben. Read more about bias.

enter image description here

<?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:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <TextView 
     android:layout_width="80dp" 
     android:layout_height="50dp" 
     android:gravity="center" 
     android:text="Hello" 
     android:textColor="@android:color/black" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="0.5" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <EditText 
     android:id="@+id/editText2" 
     android:layout_width="150dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="16dp" 
     android:ems="10" 
     android:hint="please input test content" 
     android:inputType="phone" 
     android:textColorHint="@android:color/holo_red_light" 
     android:textSize="13sp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" /> 
</android.support.constraint.ConstraintLayout> 
+0

@Cyrus 'app: layout_constraintHorizontal_bias =" 0.5 "' funktioniert nicht, weil Sie es zu keinem Elternteil eingeschränkt haben. versuche meine Antwort hoffe es hilft. –

2

Zunächst, wenn ich Sie wäre ich auf einige Führer erklären Constraint-Layouts aussehen würde, da Sie einige der wichtigsten Elemente zu sein scheinen fehlt. ConstraintLayout

Wenn das gesagt wird, ist Ihr Problem, dass Sie Ihr Layout fordern, um eine 0,5 Vorspannung auf nichts zu beschränken. Ihr TextView ist nicht auf etwas anderes als app:layout_constraintBottom_toTopOf="parent" beschränkt, was etwas seltsam ist, die Unterseite der Textansicht an die Spitze der Eltern zu beschränken.

Damit Bias funktionieren kann, muss es wissen, zwischen welchen Elementen eine Verzerrung besteht. Wenn Sie es einfach wollen Mitte der Eltern sein dann die Textview an die Mutter beschränken etwa so:

<TextView 
    android:layout_width="80dp" 
    android:layout_height="50dp" 
    android:gravity="center" 
    android:text="Hello" 
    android:textColor="@android:color/black" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintHorizontal_bias="0.5" /> 

Auch an diesem Punkt werden Sie nicht die Vorspannung benötigen, verließ ich es in aber da man dann nutzen könnten, um verschiebe es auf andere Prozentsätze.

+1

Was ich auch in der letzten Zeile hinzugefügt habe. –

Verwandte Themen