Bilal Haider
Bilal Haider

Reputation: 99

ImageButton coming out small. Java-Android Development

I have made my image buttons in XML using a relative layout. They look ok when I've made them but when I run it on my phone it comes out small! I want it to expand to the width of my device (or the width of any device it goes to)

Here's my XML:

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

<ImageButton
    android:id="@+id/prewedbutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/weddingbutton"
    android:layout_alignParentTop="true"
    android:layout_marginTop="90dp"
    android:contentDescription="@drawable/prewedbutton"
    android:src="@drawable/prewedbutton" />

<ImageButton
    android:id="@+id/weddingbutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="103dp"
    android:contentDescription="@drawable/weddingbutton"
    android:src="@drawable/weddingbutton" />

</RelativeLayout>

And here is my Java:

package com.example.ijazphotography;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.content.Intent;

public class PhotographyActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photography);
    // Show the Up button in the action bar.

        ImageButton prewed = (ImageButton) findViewById(R.id.prewedbutton);
        prewed.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), PreWedActivity.class);
                startActivityForResult(intent, 0);

            }
        });

        ImageButton wed = (ImageButton) findViewById(R.id.weddingbutton);
        wed.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), Wedding.class);
                startActivityForResult(intent, 0);
            }
        });
    }
}

Upvotes: 0

Views: 67

Answers (3)

SolArabehety
SolArabehety

Reputation: 8606

Try with android:layout_width="fill_parent" and android:scaleType="fitXY" , and tell me your results please.

Upvotes: 1

Ram kiran Pachigolla
Ram kiran Pachigolla

Reputation: 21191

If you want your buttons to occupy parent width then you can change the width of button to fill_parent

 android:layout_width="fill_parent"

Upvotes: 0

Farooq Arshed
Farooq Arshed

Reputation: 1963

change android:layout_width="wrap_content" to android:layout_width="match_parent" and it should expand to device width.

Upvotes: 0

Related Questions