我尝试使用底部导航,但按钮或图标出现在中间而不是底部,我在同一个活动中使用了抽屉导航,即我在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
发布于 2018-03-31 04:48:36
将底部的填充更改为较小的值,如下所示:
android:paddingBottom="2dp"此外,你的BottomNavigationView似乎是一个168dp大小的正方形。这是故意的吗?更改其高度或查看其布局边界。它本身可能非常大,就像一个正方形。
https://stackoverflow.com/questions/49581002
复制相似问题