Android Studio代码对齐无效
答
当使用约束布局,您需要提供一些约束它。 这里第二TextView的补充:
layout_constraintLeft_toRightOf="@id/text_view_1"
答
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"
答
有许多方法来对齐文本,但你正在尝试使用一个约束布局这是一个有点来实现这一复杂。
下面是使用与一个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>
显示您layout.xml –