2016-02-29 60 views
0

我想画的东西是这样的:垂直地画彩条 - 安卓

Color bar

鉴于条数是动态的,它必须是圆形

我试图把里面的LinearLayout意见水平方向重量和=视图数量(或圆圈内的彩条数量)

并且我把每个视图的权重= 1。然后将视图添加到LinearLayout。

问题是它不是循环的。

我怎样才能画出像这样的圆形?

+0

检查[这](http://stackoverflow.com/a/33053086/4440874)的答案。用LinearLayout替换第二个ImageView。 –

+0

@JyotmanSingh在这个答案中角落不会是透明的,他只把图片放在图片的上方。听起来不错,但不是我试图找出什么。 – MBH

回答

1

要做到这一点,你可以用这个图片http://i.stack.imgur.com/YHqsP.png阿凡达

<?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> 
+0

这里的角落不会是透明的,他们会吗?我希望它们透明 – MBH

+0

@MBH透明角落是什么意思? – Jas

+0

,因为它是矩形的,那么我会把你建议的图像放在它的上面,将被覆盖的部分将会变成***白色,并且不会看到它们背后的东西。我可以让他们看到吗? – MBH