简体   繁体   English

在 android 布局中放置三角形,并在左侧和右侧放置另一个三角形 onClick()

[英]Place triangles in android layout and put another triangle on left and right side onClick()

在此处输入图像描述

When the triangle pressed (selected), and then if I press right or left button it will add another triangle on the right or left side of the triangle I pressed.当按下(选中)三角形时,如果我按下右或左按钮,它将在我按下的三角形的右侧或左侧添加另一个三角形。

For example, lets say I clicked the main triangle (ID 100) and then I pressed the Right button, it should add a triangle on my Right, also it must assign a unique address (ID) to the new triangle例如,假设我单击了主三角形(ID 100),然后按下了右键,它应该在我的右侧添加一个三角形,并且它必须为新三角形分配一个唯一的地址(ID)

*when generating an ID for the triangle it must be 3-digit (from 101-999) *为三角形生成 ID 时,它必须是 3 位数(从 101 到 999)

For example, lets say I clicked the main triangle (ID 100) and then I pressed the Left button, it should add a triangle on my Left, also it must have a random 3-digit ID.例如,假设我点击了主三角形(ID 100)然后我按下了左按钮,它应该在我的左边添加一个三角形,它必须有一个随机的 3 位数 ID。

在此处输入图像描述

Let's say I clicked the main triangle (ID 100) and then I pressed the Left button and the Right button, it should add a triangle on my Left and also my right.假设我点击了主三角形(ID 100),然后我按下了左按钮和右按钮,它应该在我的左边和右边添加一个三角形。

If there is already a left triangle and then the user pressed Left button again, it should not add anything to the left, the same thing on the Right button.如果已经有一个左三角形,然后用户再次按下左按钮,它不应该在左边添加任何东西,在右按钮上也是一样的。

在此处输入图像描述

User clicked the triangle (111) then pressed the Left Button用户单击三角形 (111),然后按下左按钮

在此处输入图像描述

Then User clicked the new triangle (511) and pressed the Right and Left buttons And so on, I hope you got the Idea然后用户点击新的三角形(511)并按下左右按钮等等,我希望你明白了

在此处输入图像描述

How is it possible to make such layout.怎么可能做出这样的布局。 I thought to do it making many triangle layouts and putting them to single ConstraintLayout then making them android:visibility="gone" but how can I make a specific layout visible on click.我想这样做制作许多三角形布局并将它们放入单个ConstraintLayout然后使它们android:visibility="gone"但我怎样才能使特定布局在点击时可见。 I'm unable to do it in Java.我无法在 Java 中做到这一点。 What should I do??我应该怎么办??

you should set id for every view, these placed in XML should have android:id attr, these created during runtime should have setId(View.generateViewId())你应该为每个视图设置 id,这些放在 XML 应该有android:id attr,这些在运行时创建的应该有setId(View.generateViewId())

keep reference (some array? or list?) to every View and for changing visibility use view.setVisibility(View.VISIBLE)保持对每个View的引用(一些数组?或列表?)并更改可见性使用view.setVisibility(View.VISIBLE)

btw.顺便提一句。 I doubt that you achieve what you want (triangles) with separated View s, this should be done using custom drawing on some custom, extended View inside onDraw method (some DOC in here)我怀疑您是否使用分离的View实现了您想要的(三角形),这应该使用onDraw方法中的一些自定义扩展View上的自定义绘图来完成(这里有一些DOC

This kind of design typically wouldn't be a layout.这种设计通常不会是布局。 You'd use a single custom view and do the drawing yourself.您将使用单个自定义视图并自己进行绘图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM