gpt4 book ai didi

android - 在画廊 View 中显示来自特定文件夹的图像

转载 作者:行者123 更新时间:2023-11-30 03:48:11 26 4
gpt4 key购买 nike

我得到了一个画廊 View ,它根据项目内的可绘制对象显示图像。但现在我想让它显示特定文件夹的图像,但我不确定如何让它以这种方式工作。图像文件夹示例“mnt/sdcard/ff/” 任何评论和回答将不胜感激!以下是基于可绘制对象显示图像的代码。

private void setupUI() {

leftArrowImageView = (ImageView) findViewById(R.id.left_arrow_imageview);
rightArrowImageView = (ImageView) findViewById(R.id.right_arrow_imageview);
gallery = (Gallery) findViewById(R.id.gallery);

leftArrowImageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (selectedImagePosition > 0) { --selectedImagePosition; }
gallery.setSelection(selectedImagePosition, false);
}
});

rightArrowImageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (selectedImagePosition < drawables.size() - 1) { ++selectedImagePosition; }
gallery.setSelection(selectedImagePosition, false);
}
});

gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
selectedImagePosition = pos;
if (selectedImagePosition > 0 && selectedImagePosition < drawables.size() - 1) {
leftArrowImageView.setImageDrawable(getResources()
.getDrawable(R.drawable.arrow_left_enabled));
rightArrowImageView.setImageDrawable(getResources()
.getDrawable(R.drawable.arrow_right_enabled));
} else if (selectedImagePosition == 0) {
leftArrowImageView.setImageDrawable(getResources()
.getDrawable(R.drawable.arrow_left_disabled));
} else if (selectedImagePosition == drawables.size() - 1) {
rightArrowImageView.setImageDrawable(getResources()
.getDrawable(R.drawable.arrow_right_disabled));
}
changeBorderForSelectedImage(selectedImagePosition);
}

@Override
public void onNothingSelected(AdapterView<?> arg0) { }
});

galImageAdapter = new GalleryImageAdapter(this, drawables);
gallery.setAdapter(galImageAdapter);

if (drawables.size() > 0) {
gallery.setSelection(selectedImagePosition, false);
}

if (drawables.size() == 1) {
rightArrowImageView.setImageDrawable(getResources()
.getDrawable(R.drawable.arrow_right_disabled));
}

gallery.setCallbackDuringFling(false);
}

private void changeBorderForSelectedImage(int selectedItemPos) {
int count = gallery.getChildCount();

for (int i = 0; i < count; i++) {
ImageView imageView = (ImageView) gallery.getChildAt(i);
imageView.setBackgroundDrawable(getResources()
.getDrawable(R.drawable.image_border));
imageView.setPadding(3, 3, 3, 3);
}

ImageView imageView = (ImageView) gallery.getSelectedView();
imageView.setBackgroundDrawable(getResources()
.getDrawable(R.drawable.selected_image_border));
imageView.setPadding(3, 3, 3, 3);
}

private void getDrawablesList() {
drawables = new ArrayList<Drawable>();
drawables.add(getResources().getDrawable(R.drawable.ads1));
drawables.add(getResources().getDrawable(R.drawable.ads2));
drawables.add(getResources().getDrawable(R.drawable.ads3));
drawables.add(getResources().getDrawable(R.drawable.ads4));
drawables.add(getResources().getDrawable(R.drawable.ads5));
drawables.add(getResources().getDrawable(R.drawable.ads6));
drawables.add(getResources().getDrawable(R.drawable.ads7));
}

最佳答案

在名为 raw ( res/raw) 的 res 中创建新文件夹,并将图像放在这里。

并获取图像 R.raw.imagename................................

关于android - 在画廊 View 中显示来自特定文件夹的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14600553/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com