PopupMenu
类。首先获取按钮视图,然后调用show()
方法显示菜单。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和自定义适配器来创建一个简单的照片墙效果。你可以根据需要调整图片的大小、间距等参数。java,Collections.sort(dataList, new Comparator() {, @Override, public int compare(Data d1, Data d2) {, return d1.getTime().compareTo(d2.getTime());, },});,
``,,这样就可以根据数据的时间戳进行升序排序。Notification
类和 NotificationManager
来实现状态栏添加图标。以下是一个简单的函数实例:,,``java,public void addStatusBarIcon(Context context) {, Notification notification = new Notification.Builder(context), .setSmallIcon(R.drawable.icon), .setContentTitle("状态栏通知"), .setContentText("这是一个示例通知"), .build();, , NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);, notificationManager.notify(1, notification);,},
``,,这个函数会在设备的状态栏上显示一个带有指定图标的通知。DatePickerDialog
实现滚动日期选择器。通过调用show()
方法显示对话框,用户可通过滚动选择年、月、日。Powered By Z-BlogPHP 1.7.3