JamWill
JamWill

Reputation: 134

Button dissapears when run in emulator

As the title suggests. Button is clearly present and visible in Android Studio. I run the emulator and it dissapears. I have done numerous searches but cant seem to find a case-specific solution. Could you please take a look and see if you can spot something I cannot.

activity_main.xml:

<Button
        android:id="@+id/searchBtn"
        android:layout_width="300dp"
        android:layout_height="50dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="154dp"
        android:layout_marginTop="581dp"
        android:layout_marginEnd="156dp"
        android:layout_marginBottom="87dp"
        android:background="@drawable/buttons"
        android:elevation="15dp"
        android:text="SEARCH"
        android:visibility="visible" />

MainActivity.Java:

private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = findViewById(R.id.searchBtn);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openListActivity();
            }
        });
    }

    public void openListActivity() {
        Intent intent = new Intent(this, ListActivity.class);
        startActivity(intent);
    }

The buttons sole purpose at the moment is to open a second activity.

Is there any other potentially relevant code I have missed?

Upvotes: 0

Views: 46

Answers (1)

Simeon Ikudabo
Simeon Ikudabo

Reputation: 2190

Your margin is too large for the button to render to an immulator or regular device. As you know, the margin is going to put space between your widget and other widgets on the screen. But spacing of that magnitude will force your image to disappear completely. I would reduce my margin and define a more practical layout as your project grows. That should resolve your issue.

Upvotes: 1

Related Questions