Создание XML-файла для предварительного просмотра
displayfulimage.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llFullImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgvFullImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.65" />
<TextView
android:id="@+id/txtImageName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:text="Image Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"/>
</LinearLayout>
Проверьте следующий код. Это может помочь
На что следует обратить внимание ::: 1. getView () 2. onItemClick ()
public class MembersGallery extends Activity implements OnItemClickListener{
GridView gvMembers;
int values[]={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e,R.drawable.f};
ImageView im;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.memberimages);
gvMembers =(GridView)findViewById(R.id.gvMembers);
MyAdapter myad = new MyAdapter();
gvMembers.setAdapter(myad);
gvMembers.setOnItemClickListener(this);
}
class MyAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return values.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
im=new ImageView(MembersGallery.this);
im.setPadding(6, 6, 6, 6);
im.setLayoutParams(new GridView.LayoutParams(85,85));
im.setImageResource(values[position]);
return im;
}
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
//Toast.makeText(this," Clicked", 30).show();
ImageView rImage = new ImageView(this);
rImage.setImageResource(values[arg2]);
displayFullImage(rImage,250,250);
}
private void displayFullImage(ImageView im2, int width, int height) {
// TODO Auto-generated method stub
ImageView tempImageView = im2;
AlertDialog.Builder imageDialog = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.displayfulimage,
(ViewGroup) findViewById(R.id.llFullImage));
ImageView image = (ImageView) layout.findViewById(R.id.imgvFullImage);
image.setImageDrawable(tempImageView.getDrawable());
imageDialog.setView(layout);
imageDialog.setPositiveButton("OK", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
imageDialog.create();
imageDialog.show();
}
}