2017-10-08 51 views
1

在我的應用程序中,我目前在警報對話框中有兩個文本視圖來顯示溫度和天氣描述。這個問題是,只要描述發生變化,對齊就會改變。如何在Android Studio中正確地對齊我的文本?

我試圖讓我的佈局作爲一個相對佈局和移動他們兩個取決於其中一個,但這並沒有幫助我。有什麼建議麼?

這是我當前的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 


    <TextView 
     android:id="@+id/climaText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_alignStart="@+id/desc" 
     android:layout_marginTop="18dp" 
     android:layout_marginStart="120dp" 
     android:textColor="@android:color/white" /> 

    <TextView 
     android:id="@+id/desc" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/climaText" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="13dp" 
     android:textColor="@android:color/white" /> 



</RelativeLayout> 

回答

0

這是由於發生在數據大小來改變,當數據增加將包裝數據時,您將使用WRAP_CONTENT。我建議你可以使用父視圖並修正height.here是代碼,讓我知道它的工作。謝謝

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="250px"> 

     <TextView 
      android:id="@+id/climaText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_alignStart="@+id/desc" 
      android:layout_marginStart="120dp" 
      android:layout_marginTop="18dp" 
      android:textColor="@android:color/white" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="250px"> 

     <TextView 
      android:id="@+id/desc" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/climaText" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="13dp" 
      android:textColor="@android:color/white" /> 

    </LinearLayout> 

</LinearLayout> 
+0

對不起,這沒有奏效。 –