Android Studio: Image Buttons Not Showing Full Image

1.2k Views Asked by At

Image Buttons Are Only Showing a Small, Zoomed-In Piece of the Image. I don't want the image to be full size. I want to see the full picture, just smaller. How do I do this? I'm trying to make a digital marketplace type of app, like this.

2

There are 2 best solutions below

0
On

Try this. It will surely work.

<ImageButton android:id="@+id/img" android:src="@drawable/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" android:maxWidth="100dp" android:maxHeight="100dp" android:scaleType="fitCenter" android:layout_alignParentLeft="true" android:contentDescription="@string/img"/>

0
On

You can make an marketing app easily with the help of gridview and aligment would be great

//xml

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/gridview"
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent"
   android:columnWidth="90dp"
   android:numColumns="auto_fit"
   android:verticalSpacing="10dp"
   android:horizontalSpacing="10dp"
   android:stretchMode="columnWidth"
   android:gravity="center"
 />

//Sample.java

 import android.app.Activity;
 import android.os.Bundle;
 import android.widget.GridView;


public class Sample extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(Sample.this));
   }
  }

//ImageAdapter.java

 import android.content.Context;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
 import android.widget.GridView;
 import android.widget.ImageView;

      public class ImageAdapter extends BaseAdapter {
         private Context mContext;

 // Constructor
     public ImageAdapter(Context c) {
     mContext = c;
  }

public int getCount() {
    return mThumbIds.length;
}

 public Object getItem(int position) {
      return null;
}

public long getItemId(int position) {
    return 0;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;

    if (convertView == null) {
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(170, 170));

        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    } else {
        imageView = (ImageView) convertView;
    }
    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

// Keep all Images in array
public Integer[] mThumbIds = {
 //here you can place the image
    R.drawable.ic_radio_2, R.drawable.ic_radio_3,
    R.drawable.ic_radio_4, R.drawable.ic_radio_5,
    R.drawable.ic_radio_4, R.drawable.ic_radio_6,

};
}