如何强制底部导航中的按钮位于android studio的底部

时间:2018-03-30 20:26:36

标签: android

我正在尝试使用底部导航,但按钮或图标出现在中间不在底部,我在同一活动中使用抽屉导航,即我在xml资源布局中声明抽屉布局。

?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout 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"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Hello"/>

    </LinearLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="168dp"
        android:layout_height="168dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

     <android.support.design.widget.NavigationView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:menu="@menu/drawer"
      android:layout_gravity="start">


     </android.support.design.widget.NavigationView>

此活动的代码:

package com.example.welcome.madrasti;

import android.content.ClipData;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;




public class MainActivity extends AppCompatActivity {

    private TextView mTextMessage;

    Intent intent1;

    private DrawerLayout d;
    private ActionBarDrawerToggle a;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_dashboard:

                    return true;
                case R.id.navigation_home:

                    return true;
            }
            return false;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        d = (DrawerLayout) findViewById(R.id.container);
        a= new ActionBarDrawerToggle(MainActivity.this,d,R.string.open,R.string.close);

        d.addDrawerListener(a);
        a.syncState();

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        intent1= new Intent(getApplicationContext(),MapsActivity.class);


        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(a.onOptionsItemSelected(item)){

                   return  true;
        }
        return super.onOptionsItemSelected(item);
    }
}

有什么想法吗?我的底部导航如下:here

1 个答案:

答案 0 :(得分:0)

将底部的填充更改为小值,如:

android:paddingBottom="2dp"

此外,您的BottomNavigationView似乎是168dp大小的正方形。这是故意的吗?更改它的高度或查看其布局边界。它可能就像一个正方形一样非常大。