【问题标题】:bottom tool bar border not matching the height of the toolbar android studio底部工具栏边框与工具栏android studio的高度不匹配
【发布时间】:2018-06-27 12:38:58
【问题描述】:

我试图让我的按钮适合底部工具栏的边框。现在我的底部工具栏看起来像这样。

以及底部工具栏的以下 xml 文件。

 <android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:background="@drawable/white_grey_border_bottom"
    android:gravity="bottom"
    android:minHeight="?attr/actionBarSize"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingEnd="16dp"
        android:paddingStart="16dp">

        <Button
            android:id="@+id/homeIcon"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginBottom="8dp"
            android:background="@drawable/home" />


        <Button
            android:id="@+id/calendarIcon"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginBottom="8dp"
            android:layout_marginStart="32dp"
            android:background="@drawable/calendar_alt" />


        <Button
            android:id="@+id/heartIcon"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginStart="124dp"
            android:background="@drawable/oval_84" />


        <Button
            android:id="@+id/userIcon"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="32dp"
            android:background="@drawable/user" />


    </LinearLayout>

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

<Button
    android:id="@+id/floatingActionButton"
    android:layout_width="58dp"
    android:layout_height="58dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="24dp"
    android:background="@drawable/group" />

浮动操作按钮旨在突出工具栏之外,但我的其余图标应在边框内。我使用这个可绘制资源来设置我的边框。

white_grey_border xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="1dp">

<item
    android:bottom="-1dp"
    android:right="-1dp"
    android:left="-1dp"
    android:top="11dp">


<shape
    android:shape="rectangle">
    <stroke android:width="0.5dp"
        android:color="@color/colorGrey"/>
    <solid android:color="@color/colorWhite"/>
</shape>

</item>

以前我的按钮在工具栏和线性布局高度内,但在添加边框后它不适合工具栏的高度,因此灰色图标突出。提前谢谢你:)

【问题讨论】:

  • 使用BottomNavigationView不是更方便吗?
  • 我想自定义每个图标的间距,因为我希望浮动操作按钮伸出边框,因此日历和心形图标之间的间隙更大。我不确定如何使用底部导航视图来做到这一点,因为它们需要图标之间的间距相等。

标签: java android


【解决方案1】:

您可以使用组件“视图”而不是具有“1dp”高度的可绘制背景。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <View android:layout_height="1dp" android:layout_width="match_parent"/>
    <Toolbar />
    ...
</LinearLayout>

我认为底部工具栏边框与工具栏的高度不匹配,因为你为你的可绘制布局设置了 layout_height="1dp" 并且它覆盖了工具栏组件的 "layout_height"。

附言你需要使用底部导航组件而不是工具栏

【讨论】:

  • 嗨,抱歉,您能否发布整个代码>
【解决方案2】:

哎呀,我想我已经解决了,我可以将白色灰色边框 xml 的顶部从 11dp 更改为 1 dp 或 sth 。感谢您的回答。

【讨论】:

    猜你喜欢
    • 2015-11-23
    • 2015-08-28
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 2018-06-19
    • 2015-11-02
    相关资源
    最近更新 更多