简体   繁体   English

Android 如何实现基于箭头的布局?

[英]Android how can I achieve a arrow based layout?

I want to know how is possible to achieve a arrow-based layout like this :我想知道如何实现这样的基于箭头的布局:

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

Any idea about what Layout is using this app in order to achieve that layout ?知道什么 Layout 正在使用这个应用程序来实现那个布局吗? It seems like a kind of Staggered Grid Layout maybe ?这似乎是一种交错网格布局? Or maybe is using a library or a custom layout ?或者可能正在使用库或自定义布局? How can I achieve something similar ?我怎样才能实现类似的目标?

so here is how I would do something like this.所以这就是我将如何做这样的事情。

I make a bunch of custom views.我做了一堆自定义视图。

custom view #1: PokemonView.自定义视图 #1:PokemonView。 This is a regular Constraint Layout or CardView that contains all the items to show the pokemon, and its name, and all the other stuff.这是一个常规的约束布局或 CardView,其中包含显示 pokemon 的所有项目、它的名称以及所有其他内容。

custom view #2 EvolutionPokeminView.自定义视图 #2 EvolutionPokeminView。 this is a custom constraint layout that contains a PokemonView, and The Arrow ImageView (and TextView below), and helper methods to place the arrow in different directions.这是一个自定义约束布局,包含 PokemonView 和箭头 ImageView(和下面的 TextView),以及将箭头放置在不同方向的辅助方法。

for example: setArrowDirection(int direction) \\direction is some kind of enum for all directions (top, topLeft, topRight.. etc例如: setArrowDirection(int direction) \\direction 是所有方向的某种枚举(top、topLeft、topRight ......等

another helper method is setArrorPosition, setArrowPosition(int direction)另一个辅助方法是 setArrorPosition, setArrowPosition(int direction)

then you use the arrow direction method to set the correct arrow image into the arrowImageView, and you use the arrow position method to use ConstraintSet to programmatically set the correct position of the arrow in relation to the pokemon image.然后使用箭头方向方法将正确的箭头图像设置到 arrowImageView 中,并使用箭头位置方法使用ConstraintSet以编程方式设置箭头相对于 pokemon 图像的正确位置。

after that, you prepare a few common layouts to use with different sets of data and populate them accordingly.之后,您准备一些常见的布局以用于不同的数据集并相应地填充它们。

Things you'd need to know to make this approach work.要使这种方法奏效,您需要知道的事情。 How to Make a Custom View in Android.如何在 Android 中创建自定义视图。 How to use ConstraintLayout effectively.如何有效地使用 ConstraintLayout。 How to use ConstraintSet to programmatically edit ConstraintLayout constraints.如何使用 ConstraintSet 以编程方式编辑 ConstraintLayout 约束。

It is easy...When you create the child layout for recycler view.这很容易...当您为回收者视图创建子布局时。 You need to add an extra imageView for these arrows... in the main activity, you just need to assign these arrows images to that imageView value.您需要为这些箭头添加一个额外的 imageView...在主要活动中,您只需要将这些箭头图像分配给该 imageView 值。

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

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