2011-10-24 93 views
0

我正在尝试使用相对布局创建基于按钮的菜单。我试图用掉落屏幕的按钮

android:below="" 
android:above="" 
android:toLeftOf="" 
android:toRightOf="" 

命令

我想下面的三个按钮我已经有添加一个按钮,将它们布置在网格中形成,但不是按钮调整以适应父第四个按钮代替掉到屏幕边缘以下。有没有解决这个问题的方法,因为我不希望按钮在小屏幕上丢失。这里是我的布局

<RelativeLayout android:id="@+id/level1layout" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_gravity="center_horizontal"> 

<Button android:id="@+id/OneLevel1Button" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:layout_marginRight="10dp" 
android:layout_marginLeft="10dp" 
android:layout_marginBottom="10dp" 
android:layout_marginTop="10dp" 
android:text="1" 
android:textSize="25dp" 
android:background="@drawable/warpbutton" 
android:visibility="gone"/> 

    <Button android:id="@+id/OneLevel2Button" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:layout_marginRight="10dp" 
android:layout_marginLeft="10dp" 
android:layout_marginBottom="10dp" 
android:layout_marginTop="10dp" 
android:layout_below="@id/OneLevel1Button" 
android:text="2" 
android:textSize="25dp" 
android:background="@drawable/warpbutton" 
android:visibility="gone"/> 

<Button android:id="@+id/OneLevel3Button" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:layout_marginRight="10dp" 
android:layout_marginLeft="10dp" 
android:layout_marginBottom="10dp" 
android:layout_marginTop="10dp" 
android:layout_below="@id/OneLevel2Button" 
android:text="3" 
android:textSize="25dp" 
android:background="@drawable/warpbutton" 
android:visibility="gone"/> 

<Button android:id="@+id/OneLevel4Button" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:layout_marginRight="10dp" 
android:layout_marginLeft="10dp" 
android:layout_marginBottom="10dp" 
android:layout_marginTop="10dp" 
android:layout_below="@id/OneLevel3Button" 
android:text="4" 
android:textSize="25dp" 
android:background="@drawable/warpbutton" 
android:visibility="gone"/> 

</RelativeLayout> 

的可见性设置为默认了,因为他们是隐藏在启动菜单系统更深。

回答

1

你有没有考虑过使用GridLayout? http://developer.android.com/reference/android/widget/GridLayout.html

在OP的建议,一个非常有用的网站,为GridView创建custom ButtonAdapter

+0

我可以很容易地设置其可见性,并可能有多个在同一活动中运行?哦,我可以用按钮替换[这里]使用的图像(http://developer.android.com/resources/tutorials/views/hello-gridview.html)吗? – Jack

+0

我打算在这里倒退,并提供我将提供的原始链接 - http://developer.android.com/guide/tutorials/views/hello-gridview.html 您可以发布屏幕截图或mock-你试图达到什么目的? –

+0

尽量不要说它,我想它就像愤怒的小鸟级别选择菜单。一个在网格布局中具有小编号方格的人。 – Jack