将导航栏在屏幕的Andr​​oid应用程序底部应用程序、屏幕、Andr、oid

2023-09-05 09:41:48 作者:summer°罂粟花

我要放置在屏幕底部的导航栏在我的Andr​​oid应用程序。我该怎么办呢?样品code将是有益的。

I want to place navigation bar at bottom of the screen in my Android application. How can I do that? Sample code would be helpful.

推荐答案

如果您使用的是RelativeLayout的为您的活动的根,你可以调整其他视图屏幕的底部。这一点,再加上的LinearLayout作为一个容器,将提供一个灵活的面板,将导航栏的:

If you use a RelativeLayout for the root of your activity, you can align other views to the bottom of the screen. This, combined with a LinearLayout as a container, will provide a flexible panel for putting your navigation bar in:

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

    <LinearLayout 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:orientation="horizontal">

        <Button 
        android:layout_height="wrap_content" 
        android:id="@+id/back" 
        android:text="Back"
        android:layout_width="wrap_content" />

        <Button 
        android:layout_height="wrap_content" 
        android:id="@+id/home" 
        android:text="Home" 
        android:layout_width="wrap_content" />

        <Button 
        android:layout_height="wrap_content" 
        android:id="@+id/next" 
        android:text="Next" 
        android:layout_width="wrap_content" />

    </LinearLayout>

</RelativeLayout>