Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.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 线性布局匹配父级或权重不';不能在协调器布局中工作 _Android_Android Linearlayout_Android Coordinatorlayout_Android Layout Weight_Android Layoutparams - Fatal编程技术网

Android 线性布局匹配父级或权重不';不能在协调器布局中工作

Android 线性布局匹配父级或权重不';不能在协调器布局中工作 ,android,android-linearlayout,android-coordinatorlayout,android-layout-weight,android-layoutparams,Android,Android Linearlayout,Android Coordinatorlayout,Android Layout Weight,Android Layoutparams,但结果是: 线性布局与父级不匹配,或者我怀疑应用于两个浮动按钮的布局权重在协调器布局中不起作用 这是因为FloatingActionButton只能有一个固定的大小 您可以在它们之间添加一些空间 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/andr

但结果是:


线性布局与父级不匹配,或者我怀疑应用于两个浮动按钮的布局权重在协调器布局中不起作用

这是因为
FloatingActionButton
只能有一个固定的大小

您可以在它们之间添加一些空间

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.now.sexyfacechanger.Activity_PhotoOrGallery">

    <include layout="@layout/content_activity__photo_or_gallery" />

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

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_camera"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_camera"
            android:layout_weight="1"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_gallery"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_gallery"
            android:layout_weight="1"/>

    </LinearLayout>


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

这是因为
FloatingActionButton
只能具有固定的大小

您可以在它们之间添加一些空间

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.now.sexyfacechanger.Activity_PhotoOrGallery">

    <include layout="@layout/content_activity__photo_or_gallery" />

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

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_camera"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_camera"
            android:layout_weight="1"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_gallery"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_gallery"
            android:layout_weight="1"/>

    </LinearLayout>


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

因此,如果您使用LinearLayout,它可能会对您有所帮助

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal">
    <Space    
        android:layout_weight="1"     
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_camera"/>
    <Space    
        android:layout_weight="2"     
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_gallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_gallery"/>
    <Space    
        android:layout_weight="1"     
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
</LinearLayout>


因此,如果您使用线性布局,它可能会对您有所帮助

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal">
    <Space    
        android:layout_weight="1"     
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_camera"/>
    <Space    
        android:layout_weight="2"     
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_gallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_gallery"/>
    <Space    
        android:layout_weight="1"     
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
</LinearLayout>


您是否尝试过
android:layout_gravity=“bottom | center_horizontal”
@SelçukCihan刚刚尝试过,不起作用:/能否将
android:layout_width=“match_parent”
更改为
android:layou width=“wrap_content”
线性布局?@SelçukCihan谢谢,现在两个晶圆厂位于底部和中心水平位置。但我想要的视图是将视图分成两半,每个晶圆厂中心在每一半中保持水平。想知道这个问题的原因和解决方案。请检查这个答案。您是否尝试过
android:layout\u gravity=“bottom\124; center\u horizontal”
@SelçukCihan刚刚尝试过,不起作用:/能否将
android:layout\u width=“match\u parent”
更改为
android:layou width=“wrap\u content”
在线性布局中?@SelçukCihan谢谢,现在两个晶圆厂位于底部和中心水平位置。但我想要的视图是将视图分成两半,每个晶圆厂中心在每一半中保持水平。想知道这个问题的原因和解决方法。请检查这个答案