2016-02-29 58 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