2015-11-26 113 views
0

我正在为我的应用程序构建底部Toolbar。它应该看起来就像从谷歌设计的这个例子:完全从底部工具栏中删除填充?

enter image description here

我的问题是,我不能让在底部工具栏左侧的小“P”的形象,以充满整个工具栏。总是有一个小填充。当我手动将工具栏大小更改为更薄时,还有用于跳过和暂停的图像按钮不会很好地在工具栏中居中。看看我现在的工具栏:

enter image description here

看看我的布局文件的工具栏:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar_bottom" 
    android:layout_width="match_parent" 
    android:layout_height="24dp" 
    android:background="@android:color/white" 
    android:minHeight="24dp" 
    android:layout_alignParentBottom="true" 
    app:elevation="4dp" 
    app:contentInsetLeft="0dp" 
    app:contentInsetStart="0dp" 
    app:contentInsetRight="0dp" 
    android:padding="0dp" 
    android:layout_margin="0dp"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:layout_margin="0dp" 
     android:padding="0dp" 
     android:gravity="center_vertical"> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:src="@mipmap/ic_launcher"/> 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="3"> 
      <ImageButton 
       android:id="@+id/btn_skip_previous" 
       android:layout_width="20dp" 
       android:layout_height="20dp" 
       android:src="@drawable/ic_skip_previous_black" 
       style="@style/Widget.AppCompat.ActionButton" /> 
      <ImageButton 
       android:id="@+id/btn_playpause" 
       android:layout_width="20dp" 
       android:layout_height="20dp" 
       android:layout_toRightOf="@id/btn_skip_previous" 
       android:src="@drawable/ic_pause_black" 
       style="@style/Widget.AppCompat.ActionButton" /> 
      <ImageButton 
       android:id="@+id/btn_skip_next" 
       android:layout_width="20dp" 
       android:layout_height="20dp" 
       android:layout_toRightOf="@id/btn_playpause" 
       android:src="@drawable/ic_skip_next_black" 
       style="@style/Widget.AppCompat.ActionButton" /> 
     </RelativeLayout> 
    </LinearLayout> 
</android.support.v7.widget.Toolbar> 

请帮助我,我怎样才能得到底部工具栏像在第一张照片? ?

编辑:这是我得到丹尼尔Lews提示。这些符号现在被安排好,但仍然有很多的填充所有的地方:

enter image description here

+0

你想textview呢? –

+0

尝试android:padding =“0dp” - > padingLeft = 0dp –

+0

嗨,不,我不需要textview,只是第一行下方的另外两个按钮来控制亮度和速度。按下时,他们应该向上移动工具栏并显示两个滑块来设置值。但这是我的最终目标,现在它将是很好的实现工具栏中的图片示例,并知道如何有效地控制尺寸... – breakout

回答

0

您对Toolbarandroid:minHeight="24dp"集,因此它的保证是至少24dp高。尝试删除android:minHeight。 (大部分你已经在试图解决这个问题也很可能被移除设置其他属性)


至于中心的控制 - 没有布局属性告诉他们居中右现在!有多种方式来解决这个问题:

  1. 设置父RelativeLayout拥有的wrap_content的高度,然后用重力center_vertical
  2. 设置每个孩子以android:layout_centerVertical="true"为中心。
  3. 将每个孩子的身高设置为match_parent,然后使用android:gravity来设置每个孩子的内容应该放在哪里。

...而且我相信还有更多的方法。

您可能需要将RelativeLayout更改为带有砝码的LinearLayout,以便您可以将所有按钮以水平方式正确地间隔开。

+0

我根据你的建议编辑过,但我的工具栏中仍然有很多不需要的填充: – breakout