使用ImageButton的Horizontalscrollview

土贝丝

我正在使用以下示例:http : //android-er.blogspot.com/2012/07/implement-gallery-like.html来实现horizo​​ntalscrollview“画廊”,但我使用的是imagebuttons而不是imageview。我的屏幕上有3个水平滚动视图,我希望用户能够从每个滚动视图中选择一个图像,并且当用户按下按钮将选定的图像发送到新活动时。如果真的有什么我真的想知道如何从每个滚动视图中获取选定的图像到一个新的活动。如何实现用户选择的内容并在另一个活动中获得它?我是新开发的android。

奥沙伊尔甘

在名为“ insertPhoto”的方法中添加的View上实现onClick侦听器。并将视图标签设置为文件路径。

因此,单击该视图时,您将知道单击了哪个视图,并且可以从此处检查视图的标记以获取文件路径。

编辑 :

View insertPhoto(String path){

     Bitmap bm = decodeSampledBitmapFromUri(path, 220, 220);

     LinearLayout layout = new LinearLayout(getApplicationContext());
     layout.setLayoutParams(new LayoutParams(250, 250));
     layout.setGravity(Gravity.CENTER);

     ImageView imageView = new ImageView(getApplicationContext());
     imageView.setLayoutParams(new LayoutParams(220, 220));
     imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
     imageView.setImageBitmap(bm);

     layout.addView(imageView);

     layout.setTag(path);
     layout.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String filePath = (String) v.getTag();
        }
    });

     return layout;
 }


/**
 * Starts YourActivity Activity.
 * 
 * @param context   Activity Context.
 * @param filePath  URI of the File to be uploaded.
 */
public static void startPrinterActivity(Context context, String filePath) {
    Intent intent = new Intent(context, YourActivity.class);
    intent.putExtra("file_path", filePath);
    context.startActivity(intent); 
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用ImageButton打开URL

PaddingTop无法在ImageButton上使用

如何使用透明的ImageButton:Android

在片段中使用Imagebutton的NullPointerException

使用onFling更改Imagebutton图像

Android:使用Picasso延迟在horizontalscrollview中加载图像

仅使用xml的圆角ImageButton吗?

使用ImageButton android分享到Whatsapp

LibGDX:在皮肤中使用ImageButton的着色图像

在Android Eclipse IDE中使用ImageButton

使用srcCompat时ImageButton不会显示图像

使用`?attr /`时ImageButton的Espresso InflateException

如何在点击时使用ImageButton?

如何在 ImageButton 中使用 Glide?

如何使用 imagebutton 从片段中打开活动?

当我使用scale:fitxy时,我的horizontalscrollview正在拉伸我的图像按钮

将ImageButton的默认背景设置为透明(使用AndroidX)

如何使用LinearLayout均匀分布圆形的ImageButton

使用@android:drawable /以编程方式设置可绘制的ImageButton

使用ConstraintLayout在横向模式下将ImageButton居中对齐

Android-无法使用ImageButton在Listview项上执行onItemClick

Android:如何使用户选择的图像成为ImageButton的图像?

如何使用C#将ImageButton添加到标签

使用透明的ActionBar在片段的RelativeLayout中未调用ImageButton onClick

C#ASP.net使用ImageButton填充GridView

HorizontalScrollView中的ListView和ScrollView中的HorizontalScrollView

HorizontalScrollView还是Carrousel?

Android:ScrollView内的HorizontalScrollView

如何淡出HorizontalScrollView的结尾?