2013-12-14 163 views
1

我想在Android中堆疊多個(圓形)按鈕。這是我想實現的:http://imageshack.us/photo/photo/19/0gp1.jpg/在RelativeLayout中堆疊按鈕

我試圖把多個按鈕放在一個RelativeLayout中(並將它們的位置設置爲絕對位置),但是這並沒有給出我想要達到的結果,因爲按鈕並沒有實現, t在不同密度/屏幕尺寸下具有正確的位置。有沒有人有這種按鈕/佈局的經驗?我能做些什麼來達到這個結果?

+0

你可以創建這樣的drawables並將按鈕放在另一個頂部 –

+0

你需要使用ImageButton – KOTIOS

+0

我知道,但按鈕仍然是一個方形 – matthijs2704

回答

2

使它在一個RelativeView中,首先構建btn1,然後btn2,然後在另一個RelativeLayout btn3和btn4上,最後btn 5並給出背景圖像。你應該做的就是照顧他們的尺寸。

編輯:

這裏是我寫的任何代碼:

<?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" > 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" > 

     <Button 
      android:id="@+id/btn1" 
      android:layout_width="250dp" 
      android:layout_height="180dp" 
      android:text="btn1" /> 

     <Button 
      android:id="@+id/btn2" 
      android:layout_width="250dp" 
      android:layout_height="70dp" 
      android:layout_below="@+id/btn1" 
      android:text="btn2" /> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" > 

      <Button 
       android:id="@+id/btn3" 
       android:layout_width="150dp" 
       android:layout_height="75dp" 
       android:text="btn3" /> 

      <Button 
       android:id="@+id/btn4" 
       android:layout_width="150dp" 
       android:layout_height="75dp" 
       android:layout_below="@+id/btn3" 
       android:text="btn4" /> 

      <Button 
       android:id="@+id/btn5" 
       android:layout_width="50dp" 
       android:layout_height="50dp" 
       android:layout_centerInParent="true" 
       android:text="btn5" /> 
     </RelativeLayout> 
    </RelativeLayout> 

</RelativeLayout> 
+0

好的,但是當我這樣做的觸摸區,然後也圓? – matthijs2704

+0

試試吧,如果你添加背景圖片應該沒問題吧 – Rudi

+0

好的非常感謝! – matthijs2704

0

要創建這種類型的buttons你必須削減Image成不同的尺寸,並把它ImagesButton裏面Layout和使用它非常簡單。