简体   繁体   中英

Creating a main menu via XML for android app

I'm kinda new to Android (Only started studying it this year at University) and am trying to set up a main menu for my app via XML.

Basically what I want is an 20% border around my four buttons.

The below code is what I have so far, it seems to work okay but I'm not sure if I've done it the right way or not? Eclipse is currently giving me two warnings, one for the indented LinearLayout saying it might be useless, the other for the nested weights giving bad performance.

<?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来达到您想要的效果,并且权重= 8,使边框占20%(不是80%,但是操作起来很麻烦)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM