有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java向Android活动添加容器和操作栏。

我试图在顶部添加操作栏,在操作栏下方添加两个容器,每个容器的宽度分别为80%和20%

这是我的XML文件,它不工作:

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

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

    </LinearLayout>

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

    </LinearLayout>

</FrameLayout>

共 (1) 个答案

  1. # 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>