我很难将我的按钮与“login_password”的底部对齐 我已经尝试过endOf并且根本没有工作并且在父母的底部对齐而且它们似乎都没有工作。我已经尝试使用margin将其移动到底部,但它只是打破了用户名文本框。对于我遇到的问题,有没有解决方案?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@color/myBlue"
android:orientation="vertical"
android:gravity="center"
tools:context="com.vice.jake.ric.fads.view.activites.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_toStartOf="@id/relativelayout1"
android:layout_marginBottom="275dp"
android:id="@+id/relativelayout1">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="@drawable/logov3_4" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:id="@+id/relativelayout2">
<EditText
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_person_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Username"
android:padding="16dp" />
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="112dp"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_lock_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Password"
android:padding="16dp" />
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/holo_red_light"
android:layout_toEndOf="@id/login_password"
android:text="REGISTER"
android:textColor="@color/ghostWhiteColor" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't have an Account? Create one!"
android:textColor="@color/ghostWhiteColor"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</RelativeLayout>
答案 0 :(得分:3)
Use Linear Layout(orientation- vertical) with weight when working for Login screen so that it fits fine to all the screen sizes
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
android:gravity="center"
android:orientation="vertical"
android:weightSum="10">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="2"
android:src="@drawable/logov3_4" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></View>
<EditText
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/luxx_edittext"
android:drawableLeft="@drawable/ic_person_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Username"
android:padding="16dp" />
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/luxx_edittext"
android:drawableLeft="@drawable/ic_lock_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Password"
android:padding="16dp" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></View>
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/holo_red_light"
android:text="REGISTER"
android:textColor="@color/ghostWhiteColor" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"></View>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:padding="20dp"
android:text="Don't have an Account? Create one!"
android:textColor="@color/ghostWhiteColor" />
</LinearLayout>
答案 1 :(得分:0)
您可以使用LinearLayout
代替RelativeLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_toStartOf="@id/relativelayout1"
android:layout_marginBottom="275dp"
android:id="@+id/relativelayout1">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="@drawable/logov3_4" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:id="@+id/relativelayout2">
<EditText
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_person_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Username"
android:padding="16dp" />
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="112dp"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_lock_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Password"
android:padding="16dp" />
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/holo_red_light"
android:layout_toEndOf="@id/login_password"
android:text="REGISTER"
android:textColor="@color/ghostWhiteColor" />
</>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't have an Account? Create one!"
android:textColor="@color/ghostWhiteColor"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
答案 2 :(得分:0)
试试这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@color/colorAccent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="275dp"
android:src="@drawable/places_ic_search" />
<LinearLayout
android:id="@+id/relativelayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical">
<EditText
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="@color/colorAccent"
android:drawablePadding="15dp"
android:drawableStart="@drawable/places_ic_clear"
android:hint="Username"
android:padding="16dp" />
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@color/colorPrimary"
android:drawablePadding="15dp"
android:drawableStart="@drawable/places_ic_clear"
android:hint="Password"
android:padding="16dp" />
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/login_password"
android:background="@color/colorAccent"
android:text="REGISTER"
android:textColor="#ff00" />
</LinearLayout>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:text="Don't have an Account? Create one!"
android:textColor="#ff00" />
</RelativeLayout>
<强>输出强>
答案 3 :(得分:0)
您可以使用android:layout_below
代替 android:layout_toEndOf
。
将此视图的上边缘定位在给定的锚点视图ID下方。 容纳此视图的上边距和锚视图的下边距。
android:layout_below="@id/"
<强>最后强>
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/holo_red_light"
android:layout_below="@id/login_password"
android:text="REGISTER"
android:textColor="@color/ghostWhiteColor" />
答案 4 :(得分:0)
您应该使用layout_below来对齐密码字段下方的按钮。我已重新格式化您的代码以添加该
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@color/lightBlue"
android:orientation="vertical"
android:gravity="center"
tools:context="com.vice.jake.ric.fads.view.activites.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_toStartOf="@id/relativelayout1"
android:layout_marginBottom="275dp"
android:id="@+id/relativelayout1">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="@drawable/ic_about" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:id="@+id/relativelayout2">
<EditText
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_person_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Username"
android:padding="16dp" />
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="112dp"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_lock_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Password"
android:padding="16dp" />
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/holo_red_light"
android:layout_below="@id/login_password"
android:layout_marginTop="5dp"
android:text="REGISTER"
android:textColor="@color/ghostWhiteColor" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't have an Account? Create one!"
android:textColor="@color/ghostWhiteColor"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</RelativeLayout>
答案 5 :(得分:0)
试试这个..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="#f6faf7"
android:gravity="center"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/relativelayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="275dp"
android:layout_toStartOf="@id/relativelayout1"
android:adjustViewBounds="true">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativelayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical">
<EditText
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:drawablePadding="15dp"
android:hint="Username"
android:padding="16dp" />
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="112dp"
android:drawablePadding="15dp"
android:hint="Password"
android:padding="16dp" />
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/login_password"
android:text="REGISTER" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:text="Don't have an Account? Create one!" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
答案 6 :(得分:0)
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_relative"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/container_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/second_container_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/card_linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="50dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_toStartOf="@id/relativelayout1"
android:layout_marginBottom="275dp"
android:id="@+id/relativelayout1">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:id="@+id/relativelayout2">
<EditText
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_person_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Username"
android:padding="16dp" />
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_lock_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Password"
android:padding="16dp" />
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/holo_red_light"
android:layout_toEndOf="@id/login_password"
android:text="REGISTER"
android:textColor="@color/ghostWhiteColor" />
<TextView
android:layout_width="20dp"
android:layout_height="20dp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/pay_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't have an Account? Create one!"
android:textColor="@color/ghostWhiteColor"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</RelativeLayout>
答案 7 :(得分:0)
尝试以下XML代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@color/myBlue"
android:orientation="vertical"
android:gravity="center"
tools:context="com.vice.jake.ric.fads.view.activites.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_toStartOf="@id/relativelayout1"
android:layout_marginBottom="275dp"
android:id="@+id/relativelayout1">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="@drawable/logov3_4" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:id="@+id/relativelayout2">
<EditText
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_person_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Username"
android:padding="16dp" />
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="112dp"
android:background="@drawable/luxx_edittext"
android:drawableStart="@drawable/ic_lock_outline_black_24dp"
android:drawablePadding="15dp"
android:hint="Password"
android:padding="16dp" />
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/holo_red_light"
android:layout_below="@id/login_password"
android:text="REGISTER"
android:textColor="@color/ghostWhiteColor" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't have an Account? Create one!"
android:textColor="@color/ghostWhiteColor"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</RelativeLayout>
您将获得以下输出。
答案 8 :(得分:0)
您正在将按钮与endOf对齐,这意味着edittext的右侧。您必须在edittext布局下方对齐
<Button
android:id="@+id/button_redirect_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/login_password"
android:text="REGISTER"
android:textColor="@color/ghostWhiteColor" />
所以你应该能够看到login_password下面的按钮