我该如何调整一个Android的工具栏在屏幕的底部? [英] How do I align an Android toolbar to the bottom of the screen?

查看:198
本文介绍了我该如何调整一个Android的工具栏在屏幕的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把我在屏幕底部创建了一个工具栏在我的Andr​​oid应用程序。这是我到目前为止有:

http://imgur.com/n7g4yVk

我试着将黑色栏在屏幕底部的中心坐在那里,但我无法弄清楚如何做到这一点。这是XML code我有Android Studio中至今:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT    >
    <! - 开始顶酒吧 - >
    <工具栏
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ATTR / colorPrimary背景=
        >        <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=磅
            机器人:ID =@ + ID / tvLbs
            机器人:TEXTSIZE =17dp
            机器人:文字颜色=#000000
            机器人:layout_gravity =左/>        < ImageView的
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_gravity =中心
            机器人:SRC =@绘制/标志/>
        < /工具栏>    <! - 结束顶酒吧 - >    < ImageView的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:SRC =@绘制/ week1
        />    <! - 开头的所有东西滚动 - >
    <滚动型
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>        <的LinearLayout
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            机器人:方向=垂直>
            <的TextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:文字=@字符串/总
                机器人:TEXTSIZE =45dp
                机器人:layout_gravity =中心
                机器人:ID =@ + ID / tvDisplay
                />            <按钮
                机器人:layout_width =250dp
                机器人:layout_height =WRAP_CONTENT
                机器人:文字=添加一
                机器人:layout_gravity =中心
                机器人:TEXTSIZE =20dp
                机器人:ID =@ + ID / BADD
                />            <按钮
                机器人:layout_width =250dp
                机器人:layout_height =WRAP_CONTENT
                机器人:文字=减一
                机器人:layout_gravity =中心
                机器人:TEXTSIZE =20dp
                机器人:ID =@ + ID / bSubtract
                />        < / LinearLayout中>    < /滚动型>    <! - 结束滚动的东西 - >    <工具栏
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:背景=#000000
        机器人:alignParentBottom =真正的>        < /工具栏>< / LinearLayout中>


解决方案

尝试设置的重量滚动型 - 与此:

的android:layout_weight =1

I'm trying to put a toolbar I created at the bottom of the screen in my Android app. This is what I have so far:

http://imgur.com/n7g4yVk

I'm trying to move the black bar sitting there in the center at the bottom of the screen, but I can't figure out how to do it. This is the XML code I have in Android Studio so far:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    >
    <!--Begin Top Bar-->
    <Toolbar
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Lbs"
            android:id="@+id/tvLbs"
            android:textSize="17dp"
            android:textColor="#000000"
            android:layout_gravity="left"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/logo"/>
        </Toolbar>

    <!--End Top Bar-->

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/week1"
        />

    <!--Begin all scrollable stuff-->
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/total"
                android:textSize="45dp"
                android:layout_gravity="center"
                android:id="@+id/tvDisplay"
                />

            <Button
                android:layout_width="250dp"
                android:layout_height="wrap_content"
                android:text="Add one"
                android:layout_gravity="center"
                android:textSize="20dp"
                android:id="@+id/bAdd"
                />

            <Button
                android:layout_width="250dp"
                android:layout_height="wrap_content"
                android:text="Subtract one"
                android:layout_gravity="center"
                android:textSize="20dp"
                android:id="@+id/bSubtract"
                />

        </LinearLayout>

    </ScrollView>

    <!--End Scrollable stuff-->

    <Toolbar
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:alignParentBottom="true">

        </Toolbar>

</LinearLayout>

解决方案

Try setting the weight of the ScrollView - with this:

android:layout_weight="1"

这篇关于我该如何调整一个Android的工具栏在屏幕的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆