我想从viewflipper分享当前正在查看的图片,但我无法获取正在显示的图片的名称,这是我使用的代码:
_current = _current.Right;
如果有人能帮助我,我会非常感激
答案 0 :(得分:0)
我已经使用了几次,但据我所知,viewflipper一次只显示其中一个孩子。您应该调用此方法以显示孩子:
viewFlipper.setDisplayedChild(childPosition);
代码中的循环只会设置数组的最后一个图像,如果您希望显示一个应该用于RecyclerView / ListView的图像列表。 希望这有帮助!
答案 1 :(得分:0)
可能这应该适合你:
public class imagen1 extends Activity {
public float init_x;
private ViewFlipper vf;
int gallery_grid_Images[] = {R.drawable.fondo, R.drawable.fondo2, R.drawable.fondo3,
R.drawable.fondo4, R.drawable.fondo5
};
ImageView[] views = new ImageView[gallery_grid_Images.length];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.imagen1);
ImageView imagePreview = (ImageView) findViewById(R.id.preview);
vf = (ViewFlipper) findViewById(R.id.viewFlipper);
for (int i = 0; i < gallery_grid_Images.length; i++) {
// This will create dynamic image view and add them to ViewFlipper
setFlipperImage(gallery_grid_Images[i], i);
}
vf.setOnTouchListener(new ListenerTouchViewFlipper());
}
private void setFlipperImage(int res, int index) {
Log.i("Set Filpper Called", res + "");
ImageView image = new ImageView(getApplicationContext());
image.setBackgroundResource(res);
vf.addView(image);
views[index] = image;
}
public void compartir (View v) {
int index = -1;
for (int i = 0; i < views.length; i++) {
if (views[i] == (ImageView) vf.getCurrentView())
index = i;
}
if (index == -1) {
// failed to determine the right index
Log.w("imagen1", "Could not determine the right index!");
return;
}
Uri newUri2 = Uri.parse("android.resource://" + getPackageName()
+ "/drawable/" + gallery_grid_Images[index]);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "");
shareIntent.putExtra(Intent.EXTRA_STREAM, newUri2);
shareIntent.setType("image/jpg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Compartir"));
}
}
答案 2 :(得分:0)
效果很好,你不知道我多么感谢你的帮助,我只需修改代码中的一部分,因为它给了我错误:
Uri newUri2 = Uri.parse("android.resource://" + getPackageName()
+ "/drawable/" + gallery_grid_Images[i]);
添加索引
Uri newUri2 = Uri.parse("android.resource://" + getPackageName()
+ "/drawable/" + gallery_grid_Images[index]);
非常感谢你的帮助