user5854953
user5854953

Reputation:

how to fix this layout error.buttons not placed properly?

I am having a layout problem.

When the app is opened in Samsung j+ the buttons are not properly placed. Please help. the problem is explained in the image plz see the image.

this is the image...

here is the xml code:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:layout_centerHorizontal="true"
    android:gravity="top"
    android:id="@+id/relativeLayout">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:ems="10"
        android:id="@+id/editText"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:gravity="right" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/relativeLayout"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="75sp"
        android:layout_height="75sp"
        android:text="."
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:textSize="25dp"
        android:layout_toRightOf="@+id/button3"
        android:layout_toLeftOf="@+id/button12"
        android:layout_toStartOf="@+id/button12" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="75dp"
        android:layout_height="wrap_content"
        android:text="1"
        android:id="@+id/button2"
        android:layout_above="@+id/button"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/button5"
        android:textSize="25dp" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="75dp"
        android:layout_height="wrap_content"
        android:text="2"
        android:id="@+id/button3"
        android:layout_toEndOf="@+id/button2"
        android:layout_toRightOf="@+id/button2"
        android:layout_alignTop="@+id/button5"
        android:layout_above="@+id/button4"
        android:textSize="25dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0"
        android:id="@+id/button4"
        android:layout_below="@+id/button2"
        android:layout_alignRight="@+id/button3"
        android:layout_alignEnd="@+id/button3"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="25dp" />

    <Button
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:text="3"
        android:id="@+id/button5"
        android:layout_above="@+id/button"
        android:layout_toRightOf="@+id/button4"
        android:layout_toEndOf="@+id/button4"
        android:textSize="25dp" />

    <Button
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:text="4"
        android:id="@+id/button6"
        android:layout_above="@+id/button2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="25dp" />

    <Button
        android:layout_width="75dp"
        android:layout_height="wrap_content"
        android:text="5"
        android:id="@+id/button7"
        android:layout_alignTop="@+id/button6"
        android:layout_toRightOf="@+id/button6"
        android:layout_toEndOf="@+id/button6"
        android:layout_alignBottom="@+id/button6"
        android:textSize="25dp" />

    <Button
        android:layout_width="75dp"
        android:layout_height="wrap_content"
        android:text="6"
        android:id="@+id/button8"
        android:layout_above="@+id/button3"
        android:layout_toRightOf="@+id/button3"
        android:layout_toEndOf="@+id/button3"
        android:layout_alignTop="@+id/button7"
        android:textSize="25dp" />

    <Button
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:text="7"
        android:id="@+id/button9"
        android:layout_above="@+id/button8"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="25dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="8"
        android:id="@+id/button10"
        android:layout_alignTop="@+id/button9"
        android:layout_toRightOf="@+id/button9"
        android:layout_above="@+id/button6"
        android:layout_alignRight="@+id/button7"
        android:layout_alignEnd="@+id/button7"
        android:textSize="25dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="9"
        android:id="@+id/button11"
        android:layout_above="@+id/button8"
        android:layout_toRightOf="@+id/button10"
        android:layout_alignTop="@+id/button10"
        android:layout_alignRight="@+id/button8"
        android:layout_alignEnd="@+id/button8"
        android:textSize="25dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="="
        android:id="@+id/button12"
        android:layout_toRightOf="@+id/button5"
        android:layout_below="@+id/button8"
        android:layout_alignParentBottom="true"
        android:textSize="25dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="+"
        android:id="@+id/button13"
        android:layout_alignTop="@+id/button11"
        android:layout_toRightOf="@+id/button11"
        android:layout_alignRight="@+id/button12"
        android:layout_alignEnd="@+id/button12"
        android:layout_alignBottom="@+id/button8"
        android:textSize="25dp" />

    <Button
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:text="/"
        android:id="@+id/button14"
        android:layout_above="@+id/button9"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/button10"
        android:layout_alignEnd="@+id/button10"
        android:textSize="25dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="-"
        android:id="@+id/button15"
        android:layout_alignBottom="@+id/button14"
        android:layout_alignTop="@+id/button14"
        android:layout_alignRight="@+id/button13"
        android:layout_alignEnd="@+id/button13"
        android:layout_toRightOf="@+id/button11"
        android:layout_toEndOf="@+id/button11"
        android:textSize="25dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="*"
        android:id="@+id/button16"
        android:layout_alignBottom="@+id/button14"
        android:layout_alignTop="@+id/button14"
        android:layout_toRightOf="@+id/button14"
        android:layout_toLeftOf="@+id/button15"
        android:layout_toStartOf="@+id/button15"
        android:textSize="25dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CLEAR SCREEN"
        android:id="@+id/button17"
        android:layout_above="@+id/button14"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/button15"
        android:layout_alignEnd="@+id/button15" />

</RelativeLayout>

Upvotes: 1

Views: 58

Answers (1)

Avinash Joshi
Avinash Joshi

Reputation: 1308

here is a complete responsive xml no matter what device you use it

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="2"
    android:text="CLEAR SCREEN" />

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent" 
        android:layout_weight="2"
        android:text="/"
        android:textSize="25dp" />

    <Button
        android:id="@+id/button15"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="-"
        android:textSize="25dp" />

    <Button
        android:id="@+id/button16"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="*"
        android:textSize="25dp" />

    </LinearLayout>

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button9"
                android:layout_width="0dp"
                android:layout_height="match_parent" 
                android:layout_weight="1"
                android:text="7"
                android:textSize="25dp" />

            <Button
                android:id="@+id/button10"
                android:layout_width="0dp"
                android:layout_height="match_parent" 
                android:layout_weight="1"
                android:text="8"
                android:textSize="25dp" />

            <Button
                android:id="@+id/button11"
                android:layout_width="0dp"
                android:layout_height="match_parent" 
                android:layout_weight="1"
                android:text="9"
                android:textSize="25dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button6"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="4"
                android:textSize="25dp" />

            <Button
                android:id="@+id/button7"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="5"
                android:textSize="25dp" />

            <Button
                android:id="@+id/button8"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="6"
                android:textSize="25dp" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="+"
            android:id="@+id/button13" 
            android:textSize="25dp" />
    </LinearLayout>
    </LinearLayout>

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button2"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="1"
                android:textSize="25dp" />

            <Button
                android:id="@+id/button3"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="0dp"
                android:layout_height="match_parent" 
                android:layout_weight="1"
                android:text="2"
                android:textSize="25dp" />

            <Button
                android:id="@+id/button5"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="3"
                android:textSize="25dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal">
            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:text="0"
                android:id="@+id/button4" 
                android:textSize="25dp" />
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="."
                android:id="@+id/button" 
                android:textSize="25dp" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="="
            android:id="@+id/button12"
            android:layout_toRightOf="@+id/button5"
            android:layout_below="@+id/button8"
            android:layout_alignParentBottom="true"
            android:textSize="25dp" />
    </LinearLayout>
    </LinearLayout>

</LinearLayout>

Upvotes: 1

Related Questions