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