图像按钮仅显示图像的小型放大部分。我不希望图像是全尺寸的。我希望看到完整的图片,只是更小。我该怎么做呢?我试图制作数字市场类型的应用,例如this。
答案 0 :(得分:1)
试试这个。它肯定会奏效。
<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"/>
答案 1 :(得分:0)
你可以在gridview的帮助下轻松制作营销应用程序,而且对象很棒
// 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,
};
}