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 个解决方案
#1
1
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"/>
android:layout_width="wrap_content" android:layout_height="wrap_content" android: viewbounds ="true" android:maxWidth="100dp" android:maxHeight="100dp" android:scaleType="fitCenter" android:layout_alignParentLeft="true" android:contentDescription="@string/img"/>。
#2
0
You can make an marketing app easily with the help of gridview and aligment would be great
在gridview和align的帮助下,你可以很容易地制作一个营销应用
//xml
/ / 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
/ / 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
/ / 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,
};
}
#1
1
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"/>
android:layout_width="wrap_content" android:layout_height="wrap_content" android: viewbounds ="true" android:maxWidth="100dp" android:maxHeight="100dp" android:scaleType="fitCenter" android:layout_alignParentLeft="true" android:contentDescription="@string/img"/>。
#2
0
You can make an marketing app easily with the help of gridview and aligment would be great
在gridview和align的帮助下,你可以很容易地制作一个营销应用
//xml
/ / 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
/ / 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
/ / 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,
};
}