按钮脱离屏幕
我正在尝试使用相对布局创建一个基于按钮的菜单。我试图使用
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>
可见性设置为消失,因为它们在启动时隐藏在菜单系统中更深处。
I'm trying to create a button based menu using relative layout. I am trying to lay them out in a grid formation using the
android:below=""
android:above=""
android:toLeftOf=""
android:toRightOf=""
commands
I tried to add one more button below the three buttons I already had, but instead of the buttons resizing to fit the parent the fourth button instead drops below the screen edge. Is there a work around for this because I don't want buttons to appear missing on smaller screens. Here is my layout
<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>
The visibilities are set to gone by default because they are hidden deeper in the menu system on start up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过使用 GridLayout? http://developer.android.com/reference/android/widget/GridLayout.html
根据OP的建议,这是一个非常有用的网站,创建了自定义 ButtonAdapter网格视图。
Have you considered using a GridLayout? http://developer.android.com/reference/android/widget/GridLayout.html
At OP's suggestion, a very helpful site creating a custom ButtonAdapterfor a
GridView
.