gpt4 book ai didi

android - 如何将 Android 工具栏对齐到屏幕底部?

转载 作者:太空宇宙 更新时间:2023-11-03 12:18:02 25 4
gpt4 key购买 nike

我正在尝试将我创建的工具栏放在我的 Android 应用程序的屏幕底部。这是我到目前为止所拥有的:

http://imgur.com/n7g4yVk

我想移动位于屏幕底部中央的黑条,但我不知道该怎么做。这是我目前在 Android Studio 中的 XML 代码:

<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>

最佳答案

为此目的使用 RelativeLayout 会容易得多:

<RelativeLayout ...>
<!-- top toolbar -->
<Toolbar
android:id="@+id/top_toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
>

...

</Toolbar>

<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_toolbar"
android:src="@drawable/week1"
/>

<!-- bottom toolbar -->
<Toolbar
android:id="@+id/bottom_toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:layout_alignParentBottom="true">

</Toolbar>

<!-- scrollable pane -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/image"
android:layout_above="@id/bottom_toolbar">

...

</ScrollView>
</RelativeLayout>

关于android - 如何将 Android 工具栏对齐到屏幕底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27746880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com