java,public class PhotoWallActivity extends AppCompatActivity {, private GridView gridView;, private List imageUrls;,, @Override, protected void onCreate(Bundle savedInstanceState) {, super.onCreate(savedInstanceState);, setContentView(R.layout.activity_photo_wall);,, gridView = findViewById(R.id.gridView);, imageUrls = getImageUrls(); // 获取图片URL列表,, PhotoAdapter adapter = new PhotoAdapter(this, imageUrls);, gridView.setAdapter(adapter);, },, private List getImageUrls() {, // 这里可以是从网络获取的图片URL列表, List urls = new ArrayList();, urls.add("http://example.com/image1.jpg");, urls.add("http://example.com/image2.jpg");, // 添加更多图片URL..., return urls;, },},
`,,PhotoAdapter类:,,
`java,public class PhotoAdapter extends BaseAdapter {, private Context context;, private List imageUrls;,, public PhotoAdapter(Context context, List imageUrls) {, this.context = context;, this.imageUrls = imageUrls;, },, @Override, public int getCount() {, return imageUrls.size();, },, @Override, public Object getItem(int position) {, return imageUrls.get(position);, },, @Override, public long getItemId(int position) {, return position;, },, @Override, public View getView(int position, View convertView, ViewGroup parent) {, ImageView imageView;, if (convertView == null) {, imageView = new ImageView(context);, imageView.setLayoutParams(new GridView.LayoutParams(300, 300)); // 设置图片大小, imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); // 设置缩放类型, } else {, imageView = (ImageView) convertView;, },, // 使用第三方库如Glide加载图片, Glide.with(context).load(imageUrls.get(position)).into(imageView);, return imageView;, },},
`,,布局文件(activity_photo_wall.xml):,,
`xml,,,,,,
``,,这个示例展示了如何使用GridView和自定义适配器来创建一个简单的照片墙效果。你可以根据需要调整图片的大小、间距等参数。Powered By Z-BlogPHP 1.7.3