Java 如何将底部导航视图放置在<;布局>;?

Java 如何将底部导航视图放置在<;布局>;?,java,android,xml,android-studio,bottomnavigationview,Java,Android,Xml,Android Studio,Bottomnavigationview,正如你可能猜到的,我是Android Studio的初学者。 我试图在布局中放置一个BottomNavigationView,这是SearchView所需要的,但似乎没有成功。 这是我能做的最好的了,但是BottomNavigationView仍然没有出现: <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android">

正如你可能猜到的,我是Android Studio的初学者。 我试图在布局中放置一个
BottomNavigationView
,这是
SearchView
所需要的,但似乎没有成功。 这是我能做的最好的了,但是
BottomNavigationView
仍然没有出现:

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

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <android.support.v7.widget.SearchView
        android:id="@+id/search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true" />
    <ListView
        android:id="@+id/list_view"
        android:layout_width="fill_parent"
        android:layout_height="450dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/search" />


    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        menu="@menu/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        />
</RelativeLayout>
</layout>

如果有人有任何想法,我希望得到一些帮助,提前谢谢

编辑:这是活动-(我将xml的名称activity\u main.xml更改为,以便允许我使用绑定)

公共类SearchUsers扩展AppCompative活动{
私人活动主要约束;
列表适配器;
List arrayList=新建arrayList();
私有搜索视图sv;
私有ListView lv;
私有MobileServiceClient mService=null;
私有MobileServiceTable mTable=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView导航=(BottomNavigationView)findViewById(R.id.navigation);
setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
sv=(SearchView)findviewbyd(R.id.search);
lv=(ListView)findViewById(R.id.list\u视图);
binding=DataBindingUtil.setContentView(this,R.layout.activity_main);
尝试
{
mService=新的MobileServiceClient(“https://beyondapplication.azurewebsites.net“,SearchUsers.this);
mTable=mService.getTable(users.class);
}
捕获(例外e)
{
Toast.makeText(例如,getMessage().toString(),Toast.LENGTH_LONG).show();
}
AsyncTask任务=新建AsyncTask(){
@凌驾
受保护的布尔doInBackground(Void…voids){
试一试{
List myuser=mTable.execute().get();
如果(myuser.size()!=0){
对于(int i=0;i0))
返回false;
}
});
binding.search.setActivated(true);
binding.search.setQueryHint(“按用户名搜索”);
binding.search.onActionViewExpanded();
binding.search.setIconified(false);
binding.search.clearFocus();
}
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
=新的BottomNavigationView.OnNavigationItemSelectedListener(){
@凌驾
公共布尔值onNavigationItemSelected(@NonNull MenuItem item){
开关(item.getItemId()){
案例R.id.navigation\u主页:
{
返回true;
}
案例R.id.profile:
{
}
返回true;
案例R.id.navigation\u通知:
{
返回true;
}
案例R.id.find:
startActivity(新意图(SearchUsers.this、SearchUsers.class));
覆盖转换(0,0);
返回true;
}
返回false;
}
};
}这是工作代码:

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

    <android.support.v7.widget.SearchView
        android:id="@+id/search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:focusable="true" />

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/navigation"
        android:layout_below="@+id/search" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/navigation" />
</RelativeLayout>


为什么不能使用
协调器布局
?(若要在将来获得预期结果,如滚动时隐藏等),请将相对布局高度设置为匹配父级,然后重试。如果将相对布局高度设置为匹配父级,则应解决此问题。并删除相对布局上的此方向字段,因为您的布局不是线性布局,不需要方向。并尝试使用匹配父项而不是填充父项。也许此链接可以帮助您。不幸的是,我需要使用ActivityMainBindings,然后使用问题是,我尝试使用的每一种方式,BottomNavigationView都不起作用
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.SearchView
        android:id="@+id/search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:focusable="true" />

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/navigation"
        android:layout_below="@+id/search" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/navigation" />
</RelativeLayout>