简体   繁体   English

约束布局自定义页脚

[英]Constraint Layout custom footer

I have a custom footer that is wrapped inside a constraint layout.我有一个包含在约束布局内的custom footer

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteY="25dp">

    <android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/my_toolbar"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:background="@color/white"
        android:elevation="4dp"
        android:theme="@style/CustomToolBarStyle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageButton
            android:id="@+id/imageButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="8dp"
            android:background="@null"
            android:src="@drawable/ic_action_add"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/imageButton2"
            app:layout_constraintHorizontal_chainStyle="spread_inside"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:background="@null"
            android:onClick="startRecordStatsIntent"
            android:src="@drawable/ic_action_stats"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/imageButton3"
            app:layout_constraintStart_toEndOf="@+id/imageButton"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.6" />

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="8dp"
            android:background="@null"
            android:onClick="startProfileIntent"
            android:src="@drawable/ic_action_profile"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/imageButton2"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>

In the design spec, it looks pretty good as a stand alone component.在设计规范中,它作为一个独立的组件看起来很不错。 在此处输入图片说明

However, when I try to include this footer in my other pages it looks like this:但是,当我尝试在其他页面中包含此页脚时,它看起来像这样:

在此处输入图片说明

Basically, the ImageButtons are all shifted to one side of the footer.基本上, ImageButtons都移到页脚的一侧。 Here is the code of the actual page and where I include the footer:这是实际页面的代码以及我在其中包含页脚的代码:

<android.support.constraint.ConstraintLayout 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:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:layout_editor_absoluteY="25dp">



    <include
        android:id="@+id/include2"
        layout="@layout/custom_footer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.492"
        app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>

Not sure what is going on, any ideas?不知道发生了什么,有什么想法吗?

I modify your second xml file and it works fine.我修改了你的第二个 xml 文件,它工作正常。 Just set width of include2 to match_parent只需将include2宽度设置为match_parent

 <android.support.constraint.ConstraintLayout 
           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:id="@+id/linearLayout"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           tools:context=".MainActivity"
           tools:layout_editor_absoluteY="25dp">

<include
        android:id="@+id/include2"
        layout="@layout/fragment_bottom_properties_dialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.492"
        app:layout_constraintStart_toStartOf="parent"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM