2017-05-04 14 views
0

我在我的应用程序中使用底部导航栏。它包含3个项目如下:Android,BottomNavigationView,为每个项目设置重量?

<LinearLayout 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/container" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context="com.example.MainActivity"> 



<FrameLayout 
    android:id="@+id/content" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:background="#ffffff" 
    android:layout_weight="9"> 

    <GridView 
     android:id="@+id/gvMain" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:numColumns="3" /> 
</FrameLayout> 

<android.support.design.widget.BottomNavigationView 
    android:id="@+id/navigation" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_gravity="bottom" 
    android:layout_weight="1" 
    android:background="?android:attr/windowBackground" 
    android:backgroundTint="#f5f5f5" 
    app:menu="@menu/navigation" /> 

</LinearLayout> 

这里有“@菜单/导航”代码:

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

<item 
    android:id="@+id/navigation_home" 
    android:icon="@drawable/ic_home_black_24dp" 
    android:title="Button1"/> 

<item 
    android:id="@+id/navigation_dashboard" 
    android:icon="@drawable/ic_dashboard_black_24dp" 
    android:title="Button2"/> 

<item 
    android:id="@+id/navigation_notifications" 
    android:icon="@drawable/ic_notifications_black_24dp" 
    android:title="Button3"/> 

</menu> 

现在我想以某种方式有中间的按钮采取提供的半空间和另外两个分享另一半。但是没有重量属性存在。换句话说,我想将按钮2的布局权重设置为2,将按钮1和按钮3的权重设置为1.有没有办法做到这一点?

任何帮助或技巧值得赞赏。

下面是可能有助于形状:

当前布局:

Current State

我的目标就是要改变这样的:

What I want

+0

你可以发布图像设计? –

+0

我更新了问题。 – Josh

回答

0

这里是我的建议: 您可以使用布局来替换菜单:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="52dp" 
    android:orientation="horizontal"> 

    <FrameLayout 
     android:id="@+id/fl_page_home" 
     android:layout_width="wrap_content" 
     android:layout_height="57dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <Button 

      android:layout_width="35dp" 
      android:layout_height="35dp" 
      android:layout_gravity="center_horizontal" 
      android:background="your drawable" 
      /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginTop="32dp" 
      android:text="your text" /> 

    </FrameLayout> 

    <FrameLayout 
     android:id="@+id/fl_page_dashboard" 
     android:layout_width="wrap_content" 
     android:layout_height="57dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <Button 

      android:layout_width="35dp" 
      android:layout_height="35dp" 
      android:layout_gravity="center_horizontal" 
      android:background="your drawable" 
      /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginTop="32dp" 
      android:text="your text" /> 

    </FrameLayout> 

    <FrameLayout 
     android:id="@+id/fl_page_notification" 
     android:layout_width="wrap_content" 
     android:layout_height="57dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <Button 

      android:layout_width="35dp" 
      android:layout_height="35dp" 
      android:layout_gravity="center_horizontal" 
      android:background="your drawable" 
      /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginTop="32dp" 
      android:text="your text" /> 

    </FrameLayout> 

</LinearLayout> 

和高度是flexable,你可以新建一个新的XML写这为底部的导航,然后包括你的LinearLayout。

在Java类中,您可以实现onclick监听器。

相关问题