首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在android studio中将底部导航中的按钮强制置于底部

如何在android studio中将底部导航中的按钮强制置于底部
EN

Stack Overflow用户
提问于 2018-03-31 04:26:36
回答 1查看 124关注 0票数 0

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

代码语言:javascript
复制
?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>

此活动的代码如下:

代码语言:javascript
复制
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

EN

Stack Overflow用户

发布于 2018-03-31 04:48:36

将底部的填充更改为较小的值,如下所示:

代码语言:javascript
复制
android:paddingBottom="2dp"

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

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49581002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档