tailieunhanh - Xử lý với GridView

1. Chuẩn bị một số ảnh cần hiển thị. 2. Ta sẽ tạo một gridview như một ma trận để hiển thị từng ảnh trên các ô đó trong như sau: ? 1 3. Trong Activity ta sẽ sưả lại code như sau: Mã: public class GridViewActivity extends Activity { /** Called when the activity is first created. */ public void onCreate(Bundle | Xử lý với GridView 1. Chuẩn bị một số ảnh cần hiển thị. 2. Ta sẽ tạo một gridview như một ma trận để hiển thị từng ảnh trên các ô đó trong như sau 1 GridView 2 android id @ id gridview 3 android layout_width fill_parent 4 android layout_height fill_parent 5 android columnWidth 90dp 6 android numColumns auto_fit 7 android verticalSpacing 10dp 8 android horizontal Spacing 10dp 9 android stretchMode columnW idth 10 android gravity center 3. Trong Activity ta sẽ sưả lại code như sau Mã public class GridViewActivity extends Activity Called when the activity is first created. public void onCreate Bundle savedInstance State savedInstance State setContentV iew Gridview gridview GridView findViewById gridview. setAdapter new ImageAdapter this public class ImageAdapter extends BaseAdapter private Context mContext public ImageAdapter Context c mContext c public int getCount return 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 if it s not recycled initialize some attributes imageView new ImageView mContext new 85 85 8 8 8 8 else imageView ImageView convertView mThumbIds position return imageView references to our images private Integer mThumbIds R. drawable. sample_2 . sample_3 R. drawable. sample_4 . sample_5 R. drawable. sample_6 . .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.