Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何调整2个工具栏以适应父工具栏的宽度_Android_Xml_Android Layout_Android Toolbar - Fatal编程技术网

Android 如何调整2个工具栏以适应父工具栏的宽度

Android 如何调整2个工具栏以适应父工具栏的宽度,android,xml,android-layout,android-toolbar,Android,Xml,Android Layout,Android Toolbar,我在下面的代码中有两个工具栏,我想看到它们并排出现。第一个工具栏应覆盖宽度的80%,其余的应由第二个工具栏覆盖。我该怎么做呢。我可以硬编码宽度,如200dip/100 dip,但当我更换手机时,这不起作用。。屏幕爆炸 我不确定您为什么需要它,但您可以将它们包装在线性布局中应用如下权重: <LinearLayout android:orientation="horizontal" android:layout_height="wrap_content"

我在下面的代码中有两个
工具栏
,我想看到它们并排出现。第一个工具栏应覆盖宽度的80%,其余的应由第二个工具栏覆盖。我该怎么做呢。我可以硬编码宽度,如200dip/100 dip,但当我更换手机时,这不起作用。。屏幕爆炸


我不确定您为什么需要它,但您可以将它们包装在
线性布局中
应用如下权重:

<LinearLayout 
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

    <android.support.design.widget.AppBarLayout
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="0.8"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay"
                android:layout_gravity="top|left"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar1"
        android:layout_width="0dip"
        android:layout_weight="0.2"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        android:layout_gravity="top|right"/>

</LinearLayout> 

请使用以下代码。它起作用了

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:theme="@style/AppTheme.AppBarOverlay">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="0dip"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="top|left"
            android:layout_weight="0.8"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar1"
            android:layout_width="0dip"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="top|right"
            android:layout_weight="0.2"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />


    </LinearLayout>


</android.support.design.widget.AppBarLayout>

请检查下面的解决方案,它可以帮助您

 <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="1">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                app:popupTheme="@style/AppTheme.PopupOverlay"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="top|left"
                android:layout_weight="0.8"
                android:background="?attr/colorPrimary">

            </android.support.v7.widget.Toolbar>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar1"
                app:popupTheme="@style/AppTheme.PopupOverlay"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="top|right"
                android:layout_weight="0.2"
                android:background="?attr/colorPrimary">
           </android.support.v7.widget.Toolbar>

        </LinearLayout>
    </android.support.design.widget.AppBarLayout>


您可以在工具栏内部、工具栏内部或应用程序栏内部使用LinearLayout??您可以演示一个示例吗?只需使用LinearLayout的wieghtSum属性…使用@nimraasad..下面我给出答案..请多检查我的解决方案。。。是的,我做了这样的事。。我在我的应用程序栏中使用了线性布局,它也工作得很好。事实上,我对安卓和开发非常陌生。