Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Button not showing in android app

    • 0
    • 0
    • 0
    • 3
    • 0
    • 0
    • 0
    • 1.57k
    Answer it

    Hello I have created six buttons in an app in android studio inside the Relative Layout. The buttons show OK in the preview mode of android studio but they second last one does not show when I install my app to test on a phone or an emulator. What could be the problem
    Here is my code

     

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. xmlns:tools="http://schemas.android.com/tools"
    4. android:layout_width="match_parent"
    5. android:layout_height="wrap_content"
    6. android:paddingBottom="@dimen/activity_vertical_margin"
    7. android:paddingLeft="@dimen/activity_horizontal_margin"
    8. android:paddingRight="@dimen/activity_horizontal_margin"
    9. android:paddingTop="@dimen/activity_vertical_margin"
    10. tools:context="com.example.nelson.kuzaapp.MainActivity">
    11.  
    12. <ImageView
    13. android:layout_width="match_parent"
    14. android:layout_height="match_parent"
    15. android:src="@drawable/logoo"
    16. android:contentDescription="@string/logo"
    17. android:id="@+id/logo"
    18. android:layout_marginTop="-500dp"
    19. />
    20. <!--Make query button-->
    21. <Button
    22. style="?android:textAppearanceSmall"
    23. android:layout_width="match_parent"
    24. android:layout_height="wrap_content"
    25. android:layout_marginTop="150dp"
    26. android:text="@string/make_farming_query"
    27. android:id="@+id/buttonAskExpert"
    28. android:layout_below="@+id/logo"
    29. android:layout_alignParentTop="true"
    30. android:layout_alignParentRight="true"
    31. android:layout_alignParentEnd="true"
    32. />
    33. <!--View products Button-->
    34. <Button
    35. style="?android:textAppearanceSmall"
    36. android:layout_width="match_parent"
    37. android:layout_height="wrap_content"
    38. android:layout_marginTop="16dp"
    39. android:text="@string/view_products"
    40. android:id="@+id/buttonViewProducts"
    41. android:layout_below="@+id/buttonAskExpert"
    42. android:layout_alignLeft="@+id/buttonAskExpert"
    43. android:layout_alignStart="@+id/buttonAskExpert"
    44. />
    45. <!--Farmer Login button-->
    46. <Button
    47. style="?android:textAppearanceSmall"
    48. android:layout_width="match_parent"
    49. android:layout_height="wrap_content"
    50. android:layout_marginTop="16dp"
    51. android:text="@string/farmer_login"
    52. android:id="@+id/buttonFarmerLogin"
    53. android:layout_below="@+id/buttonViewProducts"
    54. android:layout_alignLeft="@+id/buttonViewProducts"
    55. android:layout_alignStart="@+id/buttonViewProducts" />
    56. <!--Farmer registration-->
    57. <Button
    58. style="?android:textAppearanceSmall"
    59. android:layout_width="match_parent"
    60. android:layout_height="wrap_content"
    61. android:layout_marginTop="16dp"
    62. android:text="@string/farmer_registration"
    63. android:id="@+id/buttonRegisterFarmer"
    64. android:layout_below="@+id/buttonFarmerLogin"
    65. android:layout_alignLeft="@+id/buttonFarmerLogin"
    66. android:layout_alignStart="@+id/buttonFarmerLogin" />
    67. <!-- Twitter button-->
    68. <Button
    69. style="?android:textAppearanceSmall"
    70. android:layout_width="match_parent"
    71. android:layout_height="wrap_content"
    72. android:layout_marginTop="16dp"
    73. android:text="@string/follow_us_on_twitter"
    74. android:id="@+id/buttonFollowTwitter"
    75. android:layout_below="@+id/buttonRegisterFarmer"
    76. android:layout_alignLeft="@+id/buttonRegisterFarmer"
    77. android:layout_alignStart="@+id/buttonRegisterFarmer" />
    78. <!--Facebook button-->
    79. <Button
    80. style="?android:textAppearanceSmall"
    81. android:layout_width="match_parent"
    82. android:layout_height="wrap_content"
    83. android:layout_marginTop="16dp"
    84. android:text="@string/like_us_on_facebook"
    85. android:id="@+id/buttonLikeFacebook"
    86. android:layout_below="@+id/buttonFollowTwitter"
    87. android:layout_alignLeft="@+id/buttonFollowTwitter"
    88. android:layout_alignStart="@+id/buttonFollowTwitter" />
    89.  
    90.  
    91. </RelativeLayout>

 3 Answer(s)

  • Did you attach the same layout in your activity or fragment. Please share the code of your Activity/Fragment too.
    If you are attaching the same layout then you can try the following points:-

    • Remove layout_marginTop="-500dp" from the imageview
    • Use wrap_content Instead of giving match_parent to the width and height of imageview
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: