簡體   English   中英

通過XML為Android應用程序創建主菜單

[英]Creating a main menu via XML for android app

我是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來達到您想要的效果,並且權重= 8,使邊框占20%(不是80%,但是操作起來很麻煩)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM