2017-09-27 22 views
-8

我正在关注视频教程。在导师的个人电脑上,这两个textviews正确对齐,但不是我的。请让我知道最新的错误。 - 附图 - 。谢谢。Android Studio代码对齐无效

A studio image

+0

显示您layout.xml –

回答

0

当使用约束布局,您需要提供一些约束它。 这里第二TextView的补充:

layout_constraintLeft_toRightOf="@id/text_view_1" 
0
xmlns:app="http://schemas.android.com/apk/res-auto" 

,并使用

 app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintBottom_toBottomOf="xyz" 
0

有许多方法来对齐文本,但你正在尝试使用一个约束布局这是一个有点来实现这一复杂。

下面是使用与一个android:layout_toEndOf=""相对布局的例子,它被简单地用于在您的期望的TextView的端部到推动你的TextView:

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


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="30dp"> 

     <TextView 
      android:id="@+id/firstText" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:layout_marginEnd="5dp" 
      android:text="FIRST TEXT" /> 

     <TextView 
      android:id="@+id/secondText" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:layout_toEndOf="@id/firstText" 
      android:text="SECOND TEXT"/> 
    </RelativeLayout> 
</LinearLayout>