简体   繁体   中英

How do I move my button down from the top of the screen?

I am currently coding a login page and am trying to add two buttons, one login and one sign up button. The sign up button works well and moves around, but cannot move the login button down from the center of the top of the page. I am using constraint layout and need help figuring it out. I am using an XML file. My code for the two buttons is:

<Button
android:id="@+id/login"
android:layout_width="300dp"
android:layout_height="75dp"
android:layout_marginTop="300dp"
android:background="ECB100"
android:enabled="false"
android:text="Login"
android:textColor="ffffff"
app:layout_constraintBottom_toTopOf="@+id/signup"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent" />
    
<Button
android:id="@+id/signup"
android:layout_width="300dp"
android:layout_height="75dp"
android:layout_gravity="start"
android:layout_marginTop="40dp"
android:background="OC8C98"
android:enabled="false"
android:text="Sign Up"
android:textColor="ffffff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login" />

Remove this attribute from your SignUp button

app:layout_constraintHorizontal_bias="0.495"

It's not clear what you want exactly. There is some suggestion of what you can do:

  • If you want the buttons in the center:
 <Button
        android:id="@+id/login"
        android:layout_width="300dp"
        android:layout_height="75dp"
        android:background="ECB100"
        android:enabled="false"
        android:text="Login"
        android:textColor="ffffff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/signup"
        android:layout_width="300dp"
        android:layout_height="75dp"
        android:layout_gravity="start"
        android:layout_marginTop="8dp"
        android:background="OC8C98"
        android:enabled="false"
        android:text="Sign Up"
        android:textColor="ffffff"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/login" />
  • If you want the buttons in the bottom:
<Button
        android:id="@+id/login"
        android:layout_width="300dp"
        android:layout_height="75dp"
        android:layout_marginBottom="8dp"
        android:background="ECB100"
        android:enabled="false"
        android:text="Login"
        android:textColor="ffffff"
        app:layout_constraintBottom_toTopOf="@+id/signup"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <Button
        android:id="@+id/signup"
        android:layout_width="300dp"
        android:layout_height="75dp"
        android:layout_gravity="start"
        android:layout_marginBottom="8dp"
        android:background="OC8C98"
        android:enabled="false"
        android:text="Sign Up"
        android:textColor="ffffff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM