Error creating multiple buttons in XML (Android Studio)

Asked

Viewed 335 times

0

I’m creating an Android app that needs to have 20 buttons and each button of this will open a different screen. The application compiles correctly, but when arriving at the screen that has the 20 buttons it closes automatically, I realized that if I put few buttons, the screen opens normal, but I need to put the 20 buttons. What’s going on? Help me please.

`

<Button
    android:id="@+id/bA"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/ima"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_marginStart="12dp" />
<Button
    android:id="@+id/bB"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imb"
    android:layout_alignParentTop="true"
    android:layout_toEndOf="@+id/bA"
    android:layout_marginStart="9dp" />
<Button
    android:id="@+id/bC"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imc"
    android:layout_alignParentTop="true"
    android:layout_toEndOf="@+id/bB"
    android:layout_marginStart="10dp" />
<Button
    android:id="@+id/bD"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imd"
    android:layout_alignParentTop="true"
    android:layout_toEndOf="@+id/bC"
    android:layout_marginStart="12dp" />

<Button
    android:id="@+id/bE"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/ime"
    android:layout_alignParentTop="true"
    android:layout_toEndOf="@+id/bD"
    android:layout_marginStart="15dp" />

<Button
    android:id="@+id/bF"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imf"
    android:layout_alignParentTop="true"
    android:layout_toEndOf="@+id/bE"
    android:layout_marginStart="13dp" />

<Button
    android:id="@+id/bG"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/img"
    android:layout_alignParentTop="true"
    android:layout_toEndOf="@+id/bF"
    android:layout_marginStart="17dp" />

<Button
    android:id="@+id/bH"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imh"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:layout_marginEnd="8dp" />

<Button
    android:id="@+id/bI"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imi"
    android:layout_marginTop="13dp"
    android:layout_below="@+id/bA"
    android:layout_alignStart="@+id/bA" />

<Button
    android:id="@+id/bJ"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imj"
    android:layout_marginTop="0dp"
    android:layout_alignTop="@+id/bI"
    android:layout_alignStart="@+id/bB" />

<Button
    android:id="@+id/bK"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imk"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bJ"
    android:layout_alignStart="@+id/bC" />

<Button
    android:id="@+id/bL"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/iml"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bK"
    android:layout_alignStart="@+id/bD" />

<Button
    android:id="@+id/bM"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imm"
    android:layout_alignBottom="@+id/bL"
    android:layout_alignStart="@+id/bE"
    android:layout_marginTop="0dp"
    />

<Button
    android:id="@+id/bN"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imn"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bM"
    android:layout_alignStart="@+id/bF" />

<Button
    android:id="@+id/bO"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imo"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bN"
    android:layout_alignStart="@+id/bG" />

<Button
    android:id="@+id/bP"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imp"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bO"
    android:layout_alignStart="@+id/bH" />

<Button
    android:id="@+id/bQ"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imq"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bO"
    android:layout_alignStart="@+id/bH"
    />

<Button
    android:id="@+id/bR"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imr"
    android:layout_marginTop="8dp"
    android:layout_below="@+id/bI"
    android:layout_alignStart="@+id/bI" />

<Button
    android:id="@+id/bS"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/ims"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bR"
    android:layout_alignStart="@+id/bJ" />

<Button
    android:id="@+id/bT"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imt"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bS"
    android:layout_alignStart="@+id/bK" />

<Button
    android:id="@+id/bU"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imu"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bT"
    android:layout_alignStart="@+id/bL" />

<Button
    android:id="@+id/bV"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imv"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bU"
    android:layout_alignStart="@+id/bM" />

<Button
    android:id="@+id/bW"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imw"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bV"
    android:layout_alignStart="@+id/bN" />

<Button
    android:id="@+id/bX"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imx"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bW"
    android:layout_alignStart="@+id/bO" />

<Button
    android:id="@+id/bY"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imy"
    android:layout_marginTop="0dp"
    android:layout_alignBottom="@+id/bX"
    android:layout_alignStart="@+id/bP" />

<Button
    android:id="@+id/bZ"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/imz"
    android:layout_marginEnd="35dp"
    android:layout_alignParentBottom="true"
    android:layout_alignEnd="@+id/bY"
    android:layout_marginBottom="12dp" />





<pl.droidsonroids.gif.GifImageView
    android:id="@+id/play_"
    android:layout_width="80dp"
    android:layout_height="70dp"
    android:layout_marginLeft="11dp"
    android:background="@null"
    android:src="@drawable/play1"
    android:layout_alignParentBottom="true"
    android:layout_toStartOf="@+id/bS" />

`

  • Joseph appears something in the logcat ?

  • Could edit the question and put the code that generates these buttons or the layout XML?

  • needs to be button, can use imageview, textview a gridlayout, even a relativelayout, all these components have onclick method support and all Voce can change the background to appear and function as a button. " if you want to know, ask me how. riririri"

  • I edited and put the View XML that is giving problem. It is in Relativelayout

  • Friend, try to run the application, and in logcat show the error that is generated and paste here please, it will be clearer

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.