the widgets dose not appear as i arranged it in android studio

1672 views android
7

When i was trying to make calculator program the buttons appeared like that when i ran the emulator the appearance of widgets and when i rearrange the button 7 the widgets disappear the widgets disappeared the design.

The activity_main.xml code:

<?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"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button17"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button14"
        android:layout_alignTop="@+id/button11"
        android:text="*" />

    <Button
        android:id="@+id/button16"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignTop="@+id/button3"
        android:layout_marginEnd="48dp"
        android:text="/" />

    <Button
        android:id="@+id/button15"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button16"
        android:layout_alignTop="@+id/button5"
        android:text="-" />

    <Button
        android:id="@+id/button14"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button15"
        android:layout_alignTop="@+id/button"
        android:text="+" />

    <Button
        android:id="@+id/button13"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button3"
        android:layout_alignTop="@+id/button11"
        android:text="7" />

    <Button
        android:id="@+id/button12"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button2"
        android:layout_alignTop="@+id/button13"
        android:text="9" />

    <Button
        android:id="@+id/button11"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button4"
        android:layout_alignTop="@+id/button12"
        android:text="8" />

    <Button
        android:id="@+id/button9"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button2"
        android:layout_alignTop="@+id/button3"
        android:text="6" />

    <Button
        android:id="@+id/button10"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button4"
        android:layout_alignTop="@+id/button3"
        android:text="5" />

    <Button
        android:id="@+id/button5"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/button2"
        android:layout_alignTop="@+id/button6"
        android:text="3" />

    <Button
        android:id="@+id/button6"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignStart="@+id/button4"
        android:layout_marginBottom="136dp"
        android:text="2" />

    <Button
        android:id="@+id/button2"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignTop="@+id/button"
        android:layout_marginEnd="130dp"
        android:text="." />

    <Button
        android:id="@+id/button3"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignStart="@+id/button7"
        android:layout_marginBottom="204dp"
        android:text="4" />

    <Button
        android:id="@+id/button7"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/button5"
        android:layout_marginStart="42dp"
        android:text="1" />

    <Button
        android:id="@+id/button4"
        android:layout_width="47dp"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/button"
        android:layout_marginStart="132dp"
        android:text="0" />

    &l

answered question

1 Answer

5

You are using RelativeLayout which arranges views relative to each other, thus when you rearrange the button7 all the other widgets relative to button7 changes and so on. For that you have to make sure that any change in particular widget position does not affect the other. Apart form this (a simple approach) you can use LinearLayout or GridLayout for buttons in order to achieve the desired format.

posted this

Have an answer?

JD

Please login first before posting an answer.