简体   繁体   中英

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

*when generating an ID for the triangle it must be 3-digit (from 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.

在此处输入图像描述

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.

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

在此处输入图像描述

Then User clicked the new triangle (511) and pressed the Right and Left buttons And so on, I hope you got the Idea

在此处输入图像描述

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. I'm unable to do it in 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())

keep reference (some array? or list?) to every View and for changing visibility use 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)

This kind of design typically wouldn't be a layout. You'd use a single custom view and do the drawing yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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