我对 Android 还算陌生(今年才在大学开始学习),正在尝试通过 XML 为我的应用程序设置主菜单。
基本上我想要的是四个按钮周围有 20% 的边框。
下面的代码是我到目前为止所拥有的,它似乎工作正常,但我不确定我是否以正确的方式完成了它? Eclipse 目前给了我两个警告,一个是针对缩进的 LinearLayout ,说它可能没用,另一个是针对嵌套权重带来的性能不佳。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="10">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_weight="8"
android:weightSum="10" >
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="2"/>
</LinearLayout>
</LinearLayout>
最佳答案
你的布局非常好,eclipse给你警告说布局没有用,只是因为你有两个父布局,但你需要它们是2才能实现你想要的,通过给主布局的weightSum = 10父布局,给 child 设置权重=8,占边框的20%(不是80%,但它很容易操作)
关于java - 通过 XML 为 Android 应用程序创建主菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20791592/