Android ApiDemos example resolution (122): Views-& gt; Grid-& gt; 2. Phot

Source: Internet
Author: User

This example is very similar to the previous example. The getView of ImageAdapter also uses ImageView, but the data source is a group of photos in the resource file.

[Java]
Public View getView (int position, View convertView,
ViewGroup parent ){
ImageView imageView;
If (convertView = null ){
ImageView = new ImageView (mContext );
ImageView. setLayoutParams (new GridView. LayoutParams (45, 45 ));
ImageView. setAdjustViewBounds (false );
ImageView. setScaleType (ImageView. ScaleType. CENTER_CROP );
ImageView. setPadding (8, 8, 8, 8 );
} Else {
ImageView = (ImageView) convertView;
}
 
ImageView. setImageResource (mThumbIds [position]);
 
Return imageView;
}

Public View getView (int position, View convertView,
ViewGroup parent ){
ImageView imageView;
If (convertView = null ){
ImageView = new ImageView (mContext );
ImageView. setLayoutParams (new GridView. LayoutParams (45, 45 ));
ImageView. setAdjustViewBounds (false );
ImageView. setScaleType (ImageView. ScaleType. CENTER_CROP );
ImageView. setPadding (8, 8, 8, 8 );
} Else {
ImageView = (ImageView) convertView;
}

ImageView. setImageResource (mThumbIds [position]);

Return imageView;
}
If necessary, you can customize the Layout of a View. For example, if an ImageView is contained, next you can create a TextView, expand the layout in the getView of the ImageAdapter, and set the ImageView as a photo, set TextView to the photo name. In this case, the GridView is displayed in a grid, but each grid or photograph is displayed, and the name of the photograph is displayed below the photograph, similar to App Launcher.

 

Author: mapdigit
 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.