【问题标题】:Android Overlapping Image Views and clickableAndroid 重叠图像视图和可点击
【发布时间】:2015-09-24 20:43:29
【问题描述】:

嗨,我想创建这种视图,其中应该有一个中心图像视图和其他重叠它,我希望它是可点击的。我怎样才能做到这一点?

【问题讨论】:

  • 我认为只能以编程方式完成。
  • 任何 sn-p 都会有很大帮助
  • 我在这里猜测一下,使用新的材料设计方法可以做到这一点,因为视图具有 Z 属性
  • 有很多潜在的解决方案。正如丹尼尔所说,如果你的目标是 Lollipop+,你可以尝试 6 个 FAB,其中一个高于上面。出于某种原因,我认为您可以使用 PopWindow 做到这一点。您可以编写自定义视图或视图。您可以制作一个自定义手势检测器以放置在 ImageView 之上。

标签: android android-layout android-imageview android-framelayout


【解决方案1】:

您应该能够仅使用 RelativeLayout 和 ImageView 来实现。

RelativeLayout 让您可以重叠视图并随意放置它。

为了获得触摸,您可以为每个图像设置 OnClickListeners。

例子:

    RelativeLayout rl = new RelativeLayout(this);
    ImageView img1 = new ImageView(this);
    //Set imageView bitmap
    img1.setDrawable("Img");

    //Click of the image
    img1.setOnClickListener(new View.OnClickListener(){...});

    //Size of the image
    RelativeLayout.LayoutParams prms = new RelativeLayout.LayoutParams(width,height); 

    //Rules for position the view on screen
    prms.addRule(...)

    //Add image to layout
    rl.addView(img1,prms);
    setContentView(rl);

Z order 是添加到布局中的订单项。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-23
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多