我想创建这样一个视图,其中交叉点应该是单独的图像视图,因为我希望它可点击。我怎么能做到这一点?
如果我有一个动态图像列表并且我正在以编程方式创建图像视图,那将非常好,如果我现在可以添加重叠的图像视图。
提前感谢!
如果我有一个动态图像列表并且我正在以编程方式创建图像视图,那将非常好,如果我现在可以添加重叠的图像视图。
提前感谢!
![enter image description here](https://istack.dev59.com/yhFar.webp)
FrameLayout
可以使视图重叠。
例如:
FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
ImageView image = new ImageView(this);
iv.setImageResource(R.drawable.image);
ImageView cross = new ImageView(this);
i.setImageResource(R.drawable.cross);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.RIGHT | Gravity.TOP;
i.setLayoutParams(layoutParams);
frame.addView(image);
frame.addView(cross);
RelativeLayout
,其中包含两个ImageViews
。将您的图像放在第一个中,将您的第二个图像放在第二个中。相应地调整边距以将其放置在右上角。首先创建一个全新的布局,用作占位符,例如“partial_layout.xml”。然后在您的代码中,使用以下类似的代码创建一个LayoutInflater:
LayoutInflater mInflater = (LayoutInflater) this.getSystemService(this.LAYOUT_INFLATER_SERVICE);
然后尝试使用类似以下方式获取此布局的新副本:
View convertView = mInflater.inflate(R.layout.partial_layout, null);
现在将您当前的数据放入此视图中,最后将此视图添加到您的内容视图中。