我想知道如何通过SwipeRefreshLayout在gridview中随机显示图片

I want to know how to randomly display images in gridview through SwipeRefreshLayout

SwipeRefreshLayout refreshLayout = findViewById(R.id.refresh_grid);
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            getImages();
            refreshLayout.setRefreshing(false);
        }
    });

    getImages();
}

我想知道如何通过SwipeRefreshLayout在gridview中随机显示图片 我想要一个像网站 https://www.pinterest.com

这样的 UI

我想在刷新时显示随机图像以显示大量图像,你能告诉我怎么做吗? 提前谢谢你

下面是完整代码。

public class MainActivity extends AppCompatActivity {
private List<String> mImagesLinks = new ArrayList<>();
private GridView mGridView;

FloatingActionButton option_01;
FloatingActionButton option_02;
FloatingActionButton option_03;
FloatingActionButton option_04;
static final int PERMISSIONS_REQUEST = 0x0000001;
//종료팝업 전면광고 추가
private static final String TAG = "ted";
TedAdmobDialog nativeTedAdmobDialog;

int nCurrentPermission = 0;
private AdView mAdView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    MobileAds.initialize(this, getString(R.string.admob_app_id));
    mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    checkPermission();

    mGridView = findViewById(R.id.grid_view);
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            startActivity(new Intent(MainActivity.this, ImageActivity.class)
                    .putExtra("Link", mImagesLinks.get(i)));
        }
    });

    option_01 = findViewById(R.id.option_01);
    option_01.setOnClickListener(v -> {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
        startActivity(intent);
    });

    option_02 = findViewById(R.id.option_02);
    option_02.setOnClickListener(v -> {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=Project+J+Lab"));
        startActivity(intent);
    });

    option_03 = findViewById(R.id.option_03);
    option_03.setOnClickListener(v -> {
        Intent myintent = new Intent(Intent.ACTION_SEND);
        myintent.setType("text/plan");

        String shereBoday = "Your Boday Here";

        String shereSub = "\"http://play.google.com/store/apps/details?id=" + getPackageName();
        myintent.putExtra(Intent.EXTRA_SUBJECT, shereBoday);
        myintent.putExtra(Intent.EXTRA_TEXT, shereSub);
        startActivity(Intent.createChooser(myintent, "shere Using"));
    });

    option_04 = findViewById(R.id.option_04);
    option_04.setOnClickListener(v -> {
        Intent email = new Intent(Intent.ACTION_SEND);
        email.setType("plain/text");
        String[] address = {"dhsthdwjd1@gmail.com"};
        email.putExtra(Intent.EXTRA_EMAIL, address);
        email.putExtra(Intent.EXTRA_SUBJECT, getPackageName());
        email.putExtra(Intent.EXTRA_TEXT, "text");
        startActivity(email);
    });

    SwipeRefreshLayout refreshLayout = findViewById(R.id.refresh_grid);
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            getImages();
            refreshLayout.setRefreshing(false);
        }
    });

    getImages();
}

private void getImages() {
    Call<List<String>> imagesResponse = NetworkUtils.getInterface().loadImages();
    imagesResponse.enqueue(new Callback<List<String>>() {
        @Override
        public void onResponse(Call<List<String>> call, Response<List<String>> response) {
            if (response.isSuccessful()) {
                mImagesLinks = response.body();
                ImagesAdapter imagesAdapter = new ImagesAdapter(MainActivity.this, mImagesLinks);
                mGridView.setAdapter(imagesAdapter);
                imagesAdapter.notifyDataSetChanged();
            } else {
                Toast.makeText(MainActivity.this, R.string.error_response, Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFailure(Call<List<String>> call, Throwable t) {
            Toast.makeText(MainActivity.this, t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
        }
    });
}

@Override
public void onBackPressed() {
    //종료팝업 전면광고 추가
    nativeTedAdmobDialog = new TedAdmobDialog.Builder(MainActivity.this, TedAdmobDialog.AdType.NATIVE, getString(R.string.banner_ad_unit_id_native))
            .setOnBackPressListener(new OnBackPressListener() {
                @Override
                public void onReviewClick() {

                }

                @Override
                public void onFinish() {
                    finish();
                }

                @Override
                public void onAdShow() {
                    log("onAdShow");
                    nativeTedAdmobDialog.loadNative();
                }
            })
            .create();
    nativeTedAdmobDialog.show();

}

//종료팝업 전면광고 추가
private void log(String text) {
    Log.d(TAG, text);
}

private void checkPermission() {
    PermissionListener permissionlistener = new PermissionListener() {
        @Override
        public void onPermissionGranted() {
        }

        @Override
        public void onPermissionDenied(List<String> deniedPermissions) {
        }
    };

    TedPermission.with(this)
            .setPermissionListener(permissionlistener)
            .setPermissions(
                    Manifest.permission.INTERNET,
                    Manifest.permission.ACCESS_NETWORK_STATE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.SET_WALLPAPER,
                    Manifest.permission.READ_CONTACTS)
            .check();
}

}

只需在 getImages() 函数中使用 Collections.shuffle(list);

参考这个了解更多信息:https://www.geeksforgeeks.org/shuffle-or-randomize-a-list-in-java/