2017-12-03 74 views
1

我想將TextView粘貼到右上方。TextView不會粘在右邊

我的代碼是:

<?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" 
    tools:context="Test.test.MainActivity"> 

    <FrameLayout 
     android:id="@+id/fragmentContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="42dp"/> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="42dp" 
     android:layout_marginRight="0dp" 
     android:text="@string/Title1" 
     android:textSize="30dp" /> 

</android.support.constraint.ConstraintLayout> 

我嘗試設置TextView

  • android:layout_alignParentRight="true"
  • android:layout_marginRight="0dp"
  • android:layout_marginTop="0dp"

但沒有什麼工作,TextView留在左上角。

有人有解決方案的想法嗎?

UPDATE:

如何堅持留下TextView另一個TextView是堅持正確的家長嗎?

我嘗試設置懷特並沒有什麼..

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_weight="0" 
    android:layout_height="42dp" 
    app:layout_constraintRight_toRightOf="parent" 
    android:text="@string/Title1" 
    android:textSize="30dp" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    android:layout_height="42dp" 
    app:layout_constraintRight_toRightOf="parent" 
    android:text="@string/Title2" 
    android:textSize="30dp" /> 

我想textView2將堅持留textView1。

找到解決更新 我只是在textview2

  • 應用程序設置:layout_constraintBaseline_toBaselineOf = 「@ + ID/textView1」

  • 應用:layout_constraintEnd_toStartOf = 「@ + ID/textView1」

謝謝,

塔爾

回答

3

在約束佈局中,TextView權約束集父佈局右對齊向右

添加以下約束你TextView

app:layout_constraintRight_toRightOf="parent" 

這樣

<TextView 
     android:id="@+id/textViewHowMuchSigned" 
     android:layout_width="wrap_content" 
     android:layout_height="42dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:text="@string/Title" 
     android:textSize="30dp" /> 
+0

非常感謝它的工作。 – tal