【问题标题】:Horizontalscrollview with ImageButton's带有 ImageButton 的 Horizo​​ntalscrollview
【发布时间】:2014-07-30 23:24:25
【问题描述】:

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

【问题讨论】:

    标签: android horizontalscrollview


    【解决方案1】:

    在名为“insertPhoto”的方法中在要添加的视图上实现 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); 
    }
    

    【讨论】:

    • 如何通过标记视图添加选中的文件路径,我不明白你的意思。你能澄清一下吗?
    • 查看我的编辑。我在我提到的方法中添加了必要的行。
    • 谢谢!如何使用 onClick 提供的内容来放置一个按钮,该按钮将启动一个带有图像的新活动?
    • 查看我的编辑。我添加了可以运行另一个活动的方法。如果您认为该答案是正确的,请“接受它作为答案”并投票。谢谢。
    【解决方案2】:

    你想要的都在这里here,

    原来的用法是here

    部分代码......

    // bring DOWN
    if($(document).scrollTop() - containerTop > 100) {
        if($('#img2').css("margin-top") == "295px") {
            $('#img2').animate({"margin-top": "0px"}, 600);
        }
    }  
    
      // bring UP
    if($(document).scrollTop() - containerTop < 100) {
        if($('#img2').css("margin-top") == "0px") {
            $('#img2').animate({"margin-top": "295px"}, 600);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多