Mohamed
Mohamed

Reputation: 75

Android- making 2 buttons side by side

Hey guys so I did look at other questions regarding this and I even looked online and I see nothing wrong with my code but every time I try to make a AVD to check out how the app looks the buttons dont show side by side but in android studio render screen it does.

If anyone could help I would be really thankful!

This is once i load the AVD in android studio enter image description here

This is how is shows in the render in android studio enter image description here

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.jarvis.imquest.MainActivity">

    <ImageView
        android:id="@+id/image_message"
        android:src="@drawable/ic_message"
        android:layout_marginTop="20dp"
        android:layout_centerHorizontal="true"
        android:layout_width="100dp"
        android:layout_height="100dp" />

    <LinearLayout
        android:orientation="vertical"
        android:layout_below="@+id/image_message"
        android:id="@+id/group_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/main_editLogin"
                android:hint="Enter Username"
                android:padding="5dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/main_editPassword"
                android:hint="Enter Password"
                android:padding="5dp"
                android:inputType="textPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
        </android.support.design.widget.TextInputLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_below="@+id/group_login"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="2">

        <Button
            android:layout_weight="1"
            android:id="@+id/main_btnLogin"
            android:background="@color/colorPrimaryDark"
            android:textColor="@color/colorAccent"
            android:text="Login"
            android:layout_marginRight="5dp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            style="@style/Widget.AppCompat.Button.Borderless"
            />

        <Button
            android:layout_weight="1"
            android:id="@+id/main_btnSignup"
            android:background="@color/colorPrimaryDark"
            android:textColor="@color/colorAccent"
            android:text="SignUp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            style="@style/Widget.AppCompat.Button.Borderless"
            />
    </LinearLayout>


</RelativeLayout>

Upvotes: 2

Views: 2419

Answers (2)

3zcs
3zcs

Reputation: 35

try this

    <LinearLayout
    android:layout_below="@+id/group_login"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <Button
        android:id="@+id/main_btnLogin"
        android:background="@color/colorPrimaryDark"
        android:textColor="@color/colorAccent"
        android:text="Login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Widget.AppCompat.Button.Borderless"
        />

    <Button
        android:id="@+id/main_btnSignup"
        android:background="@color/colorPrimaryDark"
        android:textColor="@color/colorAccent"
        android:text="SignUp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Widget.AppCompat.Button.Borderless"
        />
</LinearLayout>

Upvotes: 0

Ferdous Ahamed
Ferdous Ahamed

Reputation: 21736

Add attribute android:weightSum="2" to your LinearLayout and remove attributeandroid:layout_toRightOf="@+id/main_btnLogin" from signup button.

Try this:

    <LinearLayout
        android:layout_below="@+id/group_login"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="2">

        <Button
            android:layout_weight="1"
            android:id="@+id/main_btnLogin"
            android:background="@color/colorPrimaryDark"
            android:textColor="@color/colorAccent"
            android:text="Login"
            android:layout_marginRight="5dp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            style="@style/Widget.AppCompat.Button.Borderless"
            />

        <Button
            android:layout_weight="1"
            android:id="@+id/main_btnSignup"
            android:background="@color/colorPrimaryDark"
            android:textColor="@color/colorAccent"
            android:text="SignUp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            style="@style/Widget.AppCompat.Button.Borderless"
            />
    </LinearLayout>

OUTPUT on my Galaxy Note3 device:

enter image description here

enter image description here

Upvotes: 4

Related Questions