我是Android Studio的begginer,我試圖垂直居中ConstraintLayout
的內容,但沒有成功。我嘗試過使用android:gravity="center"
,並刪除了所有元素的app:layout_editor_absoluteY
,但不會發生......所以,我該如何集中這個?如何將Android Studio中的ConstraintLayout內容垂直居中?
<?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"
android:background="@layout/gradient"
android:gravity="center"
tools:context="com.test.test.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<EditText
android:id="@+id/txtEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:ems="10"
android:hint="@string/lblEmail"
android:inputType="textEmailAddress"
android:textColorHint="@color/colorGray"
android:background="@color/colorWhite"
android:padding="15dp" />
<EditText
android:id="@+id/txtSenha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="@string/lblSenha"
android:inputType="textPassword"
android:textColorHint="@color/colorGray"
android:background="@color/colorWhite"
android:padding="15dp"
app:layout_constraintTop_toBottomOf="@+id/txtEmail" />
<Button
android:id="@+id/btnEntrar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="@string/lblEntrar"
app:layout_constraintTop_toBottomOf="@+id/txtSenha" />
</android.support.constraint.ConstraintLayout>
只是爲了明確要居中約束佈局或限制佈局本身裏面的元素呢? – Juanca
@Juanca我想集中裏面的元素,他們目前在頂部:/ – Igor