2014-05-23 31 views
0

我想在頂部添加動作條,並在動作條下面添加兩個容器,每個容器都有80%的寬度和20%的寬度。將容器和操作欄添加到Android活動。

這裏是一個不工作我的XML文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.hany_action_bar.MainActivity" 
    tools:ignore="MergeRootFrame" > 

    <LinearLayout 
     android:id="@+id/menu_container" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:weightSum="20" 
     android:orientation="horizontal" > 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/main_container" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:weightSum="80" 
     android:orientation="horizontal" > 

    </LinearLayout> 

</FrameLayout> 
+0

什麼是 「不工作」 是什麼意思? – Emmanuel

+2

改變'weightSum'爲'weight' – Blundell

+1

而不是'android:weightSum =「20」/「80」'使用'android:weight =「20」/「80」' – Onik

回答

-1

可以試試這樣:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="2" 
    tools:context="com.example.hany_action_bar.MainActivity" 
    tools:ignore="MergeRootFrame" > 

    <LinearLayout 
     android:id="@+id/menu_container" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="1.6" 
     android:background="#000" 
     android:orientation="horizontal" > 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/main_container" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.4" 
     android:background="#fff" 
     android:orientation="horizontal" > 
    </LinearLayout> 

</LinearLayout> 
+0

數學是錯誤的。 2的80%(根容器中定義的重量)是1.6而不是1.8。請做數學 –

+0

對不起。這是我的錯誤。它並不危險,不正確。請不要downvote這件事。它的要求。 – Dig

相關問題