7

A beehive layout should look like this

The colored hives are just so you understand how I have to lay down elements.

Which Layout widget do you suggest of using?

I tried with GridView but I cannot make such cells, then FrameLayout but don't want to deal with pixel (or dp) values when setting hive location.

I am at my wits end. I am close to conclusion that something like this cannot be done in Android in a high quality way and without using game-like libraries. I hope someone will give me a good clue to solution.

sandalone
  • 41,141
  • 63
  • 222
  • 338
  • 1
    You really aroused my curiosity and I did some googling, wondering whether it's possible. Everything indicates that no, it isn't (that is, not by simple means), and non-rectangular layouts are only achieved by "cheating", like http://stackoverflow.com/a/13879492/168719 or http://stackoverflow.com/a/19583072/168719 - in other words, they are only made to appear non-rectangular and clicking in the transparent area is just ignored to maintain that impression. In your case though it would have to be delegated to the adjacent tile, and having to handle this would further complicate the code. – Konrad Morawski Apr 15 '14 at 09:03
  • Guys, it's not an issue with making beehive shape. That is easier part. The hard part is how to place elements to be like a beehive. You see that one touches another with only half of its height. So main question is which `???Layout` to use which can support such positioning of elements. – sandalone Apr 16 '14 at 07:06
  • @MikeM. that's what I imagined, a solution that would involve some sort of an event bus through which these component views would subscribe to events and indirectly notify eachother: "is this my click? if not, delegate it to whoever you find at these coordinates, please". It's an interesting idea for a more generic project, not limited to just beehive layouts, but crazy layouts of all sorts – Konrad Morawski Apr 16 '14 at 10:50
  • @MikeM. Sure, drop it here so I can take a look as well. Of course, if you want to and if you thins it's ready to be shown. – sandalone Apr 16 '14 at 14:24
  • @MikeM. Yes. I will then be able to choose which beehive I want to make active or inactive. More important thing is to create such layout it looks nice on all types of Android screens. – sandalone Apr 17 '14 at 09:42

1 Answers1

0

This answer is too late, but someone may find the solution from this, so I am answering this question

I made a simple honeycomb view using ConstraintLayout.

here is the code, You can replace ImageView with any other view

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragment.MyFragment">

    <com.myapp.widget.CustomTextView
        android:id="@+id/iv_1"
        style="@style/tv_style"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/honey_comb_center"
        android:gravity="center"
        android:text="Total\nInvestment"
        app:fontName="@string/font_bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/iv_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/_5sdp"
        android:src="@drawable/honey_comb"
        app:layout_constraintBottom_toBottomOf="@id/iv_1"
        app:layout_constraintRight_toLeftOf="@id/iv_1"
        app:layout_constraintTop_toTopOf="@id/iv_1" />

    <ImageView
        android:id="@+id/iv_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/_5sdp"
        android:src="@drawable/honey_comb"
        app:layout_constraintBottom_toBottomOf="@id/iv_1"
        app:layout_constraintLeft_toRightOf="@id/iv_1"
        app:layout_constraintTop_toTopOf="@id/iv_1" />

    <ImageView
        android:id="@+id/iv_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/honey_comb"
        android:translationY="@dimen/_20sdp"
        app:layout_constraintBottom_toTopOf="@id/iv_1"
        app:layout_constraintLeft_toLeftOf="@id/iv_2"
        app:layout_constraintRight_toRightOf="@id/iv_1" />

    <ImageView
        android:id="@+id/iv_5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/honey_comb"
        android:translationY="@dimen/_20sdp"
        app:layout_constraintBottom_toTopOf="@id/iv_1"
        app:layout_constraintLeft_toLeftOf="@id/iv_1"
        app:layout_constraintRight_toRightOf="@id/iv_3" />

    <ImageView
        android:id="@+id/iv_6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/honey_comb"
        android:translationY="@dimen/_minus20sdp"
        app:layout_constraintLeft_toLeftOf="@id/iv_2"
        app:layout_constraintRight_toRightOf="@id/iv_1"
        app:layout_constraintTop_toBottomOf="@id/iv_1" />

    <ImageView
        android:id="@+id/iv_7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/honey_comb"
        android:translationY="@dimen/_minus20sdp"
        app:layout_constraintLeft_toLeftOf="@id/iv_1"
        app:layout_constraintRight_toRightOf="@id/iv_3"
        app:layout_constraintTop_toBottomOf="@id/iv_1" />

</androidx.constraintlayout.widget.ConstraintLayout>

here is the screenshot enter image description here

Priyanka
  • 3,369
  • 1
  • 10
  • 33