0

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?

MBH
  • 16,271
  • 19
  • 99
  • 149
  • Check [this](http://stackoverflow.com/a/33053086/4440874) answer. Just replace the second ImageView with a LinearLayout. – Jyotman Singh Feb 29 '16 at 09:42
  • @JyotmanSingh The corners wont be transparent in that answer, He puts image above the image only. sounds good trick but not what im trying to find out. – MBH Feb 29 '16 at 09:44

1 Answers1

1

To achieve this you can use this Image https://i.stack.imgur.com/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>
Avani Nagar
  • 96
  • 1
  • 11
  • The corners wont be transparent here, will they? I want them to be transparent – MBH Feb 29 '16 at 09:57
  • @MBH what do you mean by transparent corner? – Jas Feb 29 '16 at 09:59
  • as it is rectangular, then i will put the image you suggested above it, the parts that will be covered will be ***white***, and what behind them wont be seen. Can i make them to be seen ? – MBH Feb 29 '16 at 10:02
  • No, That will be of the image colour you can use the image of any colour which is transparent form inside. – Avani Nagar Feb 29 '16 at 10:03
  • for making rounded corner image you can use this [link](https://github.com/manishsri01/AndroidCustomImageView) – Avani Nagar Feb 29 '16 at 10:50