MBH
MBH

Reputation: 16639

Draw color bars vertically - android

I am trying to draw something like this:

Color bar

Whereas the bars number is dynamic, and it must be circular

I tried to put views inside LinearLayout oriented horizontally with weight sum = number of views (or number of color bars inside the circle)

and i put weight=1 for every view. then add the views to LinearLayout.

The problem is it is not circular.

How can I draw something like this to be circular as well?

Upvotes: 0

Views: 108

Answers (1)

Avani Nagar
Avani Nagar

Reputation: 96

To achieve this you can use this Image https://i.sstatic.net/YHqsP.png as avatar

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">



    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/circular_frame"
        android:layout_alignLeft="@+id/circular_frame"
        android:layout_alignRight="@+id/circular_frame"
        android:layout_alignTop="@+id/circular_frame">

        <ImageView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#aa00aa"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#aaaa00"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#0000aa"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#aa0000"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#00aaaa"/>

    </LinearLayout>
    <FrameLayout
        android:id="@+id/circular_frame"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/avatar">

    </FrameLayout>

</RelativeLayout>

Upvotes: 1

Related Questions