2013-12-14 90 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和使用它非常简单。