gpt4 book ai didi

android - 如何在协调器布局中将 LinearLayout 附加到屏幕底部?

转载 作者:行者123 更新时间:2023-12-02 10:23:25 25 4
gpt4 key购买 nike

我遇到的情况是,线性布局不会固定在协调器布局的底部,而是相对于上面的 ScrollView 内容移动。

我已经尝试了 StackOverflow 上的所有解决方案,但仍然没有运气(例如: Keep LinearLayout at the bottom of screen 甚至尝试了relativelayout,但没有运气: Make a RelativeLayout at the bottom of a Scrollview )。我不确定是什么导致了这种情况,因为线性/相对布局相对于 ScrollView 移动,但如果其他人能找出我做错或遗漏的地方,那将是一个很大的帮助!提前致谢!下面是我的 XML 代码:(如果有帮助,欢迎分享任何其他相关的 java 代码)

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:clickable="false"
android:fitsSystemWindows="true"
android:fillViewport="true"
android:id="@+id/cl_root_view"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_register_container"
android:layout_marginBottom="60dp"
android:background="@color/white"
android:orientation="vertical">

<LinearLayout
android:id="@+id/activity_register_guest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">


<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:subtitleTextColor="@color/white"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:titleTextColor="@color/white">


<!--<TextView
android:id="@+id/nav_back_btn"
style="@style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="20dp"
android:background="@drawable/ic_backarrow"
android:gravity="center_horizontal" />-->

<TextView
android:id="@+id/register_guest_main_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginTop="15dp"
android:layout_gravity="center"
android:letterSpacing="0.01"
android:textAllCaps="true"
android:text="@string/register_guest"
android:textAppearance="@style/TextAppearance.Text.Roboto.Medium"
android:textColor="#de000000"
android:textSize="17sp"
android:textStyle="normal"

/>

</android.support.v7.widget.Toolbar>


</android.support.design.widget.AppBarLayout>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="@color/white"
android:fitsSystemWindows="true"
android:layout_marginBottom="65dp">

<RelativeLayout
android:id="@+id/register_visitor_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:clickable="false"
android:fillViewport="true">

<LinearLayout
android:id="@+id/main_register_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">

<TextView
android:id="@+id/my_location"
style="@style/Headline2LeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:textAppearance="@style/TextAppearance.Text.Chronicle"
android:textSize="28sp"
tools:text="@string/five_thirty_fifth_ave" />

<TextView
style="@style/Body1RegRightRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/my_location"
android:layout_alignParentEnd="true"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_toEndOf="@+id/my_location"
android:text="@string/location_change"
android:textAppearance="@style/TextAppearance.Text.Roboto.Regular"
android:visibility="gone" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_marginTop="24dp"
android:gravity="center_vertical"
android:layout_marginBottom="8dp"
android:weightSum="2">

<TextView
android:id="@+id/select_date_and_time"
android:layout_width="wrap_content"
android:textSize="17sp"
android:lineSpacingExtra="6sp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textColor="@color/black"
android:text="@string/select_date_and_time"
android:textAppearance="@style/TextAppearance.Text.Roboto.Medium" />

</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/registerUserSeparatorColor" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:weightSum="2">

<TextView
android:id="@+id/register_guest_start_date"
style="@style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="@string/register_guest_start_date"
android:textAppearance="@style/TextAppearance.Text.Roboto.Regular" />

<TextView
android:id="@+id/register_guest_start_time"
style="@style/Body1RegRightBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:text="@string/register_guest_start_time"
android:textAppearance="@style/TextAppearance.Text.Roboto.Regular" />
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/registerUserSeparatorColor" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:weightSum="2">

<TextView
android:id="@+id/register_guest_end_date"
style="@style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="@string/register_guest_end_date"
android:textAppearance="@style/TextAppearance.Text.Roboto.Regular"
android:visibility="invisible" />

<TextView
android:id="@+id/register_guest_end_time"
style="@style/Body1RegRightBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:text="@string/register_guest_end_time"
android:textAppearance="@style/TextAppearance.Text.Roboto.Regular" />
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/registerUserSeparatorColor" />

<TextView
android:id="@+id/build_your_guest_list"
android:layout_width="wrap_content"
android:textSize="17sp"
android:layout_marginTop="42dp"
android:lineSpacingExtra="6sp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textColor="@color/black"
android:text="@string/build_your_guest_list"
android:paddingBottom="8dp"
android:textAppearance="@style/TextAppearance.Text.Roboto.Medium" />



<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/registerUserSeparatorColor" />

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="44dp"
android:id="@+id/add_guest"
android:layout_marginTop="3dp"
android:layout_marginBottom="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="44dp"
android:lineHeight="22sp"
android:drawablePadding="10dp"
android:drawableStart="@drawable/ic_add_24px"
android:drawableTint="@color/bluish"
android:layout_marginStart="17dp"
android:lineSpacingExtra="6sp"
android:textColor="@color/bluish"
android:gravity="center_vertical"
android:textAppearance="@style/TextAppearance.Text.Roboto.Medium"
android:text="@string/add_a_new_guest"
android:textSize="17sp" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/registerUserSeparatorColor"
/>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="44dp"
android:id="@+id/search_guest"
android:layout_marginTop="3dp"
android:visibility="gone"
android:layout_marginBottom="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="44dp"
android:lineHeight="22sp"
android:drawablePadding="10dp"
android:drawableStart="@drawable/ic_search_24px"
android:drawableTint="@color/bluish"
android:layout_marginStart="17dp"
android:lineSpacingExtra="6sp"
android:textColor="@color/bluish"
android:gravity="center_vertical"
android:textAppearance="@style/TextAppearance.Text.Roboto.Medium"
android:text="@string/search_past_guests"
android:textSize="17sp" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:visibility="gone"
android:id="@+id/search_guest_line"
android:background="@color/registerUserSeparatorColor"
/>

<android.support.v7.widget.RecyclerView
android:id="@+id/guest_item_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:overScrollMode="never"
tools:listitem="@layout/item_guest" />



<TextView
android:id="@+id/arrival_notifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="58dp"
android:letterSpacing="0.01"
android:lineSpacingExtra="4sp"
android:text="@string/arrival_notifications"
android:textAppearance="@style/TextAppearance.Text.Roboto.Medium"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="normal"
android:visibility="invisible" />

<RelativeLayout
android:id="@+id/text_message_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:visibility="gone">

<TextView
android:id="@+id/text_message"
style="@style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:text="@string/text_message"
android:textAppearance="@style/TextAppearance.Text.Roboto.Regular" />

<TextView
android:id="@+id/tap_phone_number_text"
style="@style/Body2RegLeftGrey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text_message"
android:layout_marginTop="2dp"
android:text="@string/tap_to_add_a_phone_number"
android:textAppearance="@style/TextAppearance.Text.Roboto.Regular" />

<android.support.v7.widget.SwitchCompat
android:id="@+id/text_message_switch"
style="@style/Color1SwitchStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp" />
</RelativeLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginTop="11dp"
android:background="@color/settingsSeparatorLineColor"
android:visibility="gone" />


</LinearLayout>

<!-- <TextView
android:id="@+id/submit_users_btn"
style="@style/LoginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="30dp"
android:letterSpacing="0.07"
android:lineSpacingExtra="0sp"
android:text="@string/submit_visitor_list"
android:textAppearance="@style/TextAppearance.Text.Roboto.Medium"
android:textSize="16sp"
android:textStyle="normal" /> -->
</RelativeLayout>
</ScrollView>

</LinearLayout>

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_gravity="center|bottom"
android:background="@color/transparent"
android:layout_marginBottom="75dp"
android:orientation="vertical"
android:id="@+id/fixedSubmitButtonlayout">
<TextView
android:id="@+id/submit_users_btn"
android:textColor="#757575"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/textview_border"
android:letterSpacing="0.07"
android:gravity="center"
android:lineSpacingExtra="0sp"
android:text="@string/register_guest_caps"
android:textAppearance="@style/TextAppearance.Text.RidleyGrotesk.Regular"
android:textSize="16sp"
android:textStyle="normal" />
</LinearLayout>

</android.support.design.widget.CoordinatorLayout>

从上面的代码中,我试图在底部修复的布局的 id 是:android:id="@+id/fixedSubmitButtonlayout"

我希望它保持完整/固定在屏幕底部,而不管其上方的 ScrollView 应该在其后面滚动(到目前为止,只是按钮位置随着 ScrollView 内容溢出屏幕大小而改变) )。有想法该怎么解决这个吗?

最佳答案

只需执行以下步骤:

  1. 添加一个RelativeLayout作为CoordinatorLayout的父级并且
  2. 从CoordinatorLayout中取出最后一个LinearLayout并
  3. 使用android:layout_alignParentBottom="true"将其添加到RelativeLayout。
  4. 请注意,您需要将 android:layout_marginBottom="40dp" 添加到 CoordinatorLayout

你可以尝试这个(经过测试,效果很好):

<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="match_parent"
>

<your CoordinatorLayout>

</your CoordinatorLayout>

<LinearLayout
android:id="@+id/fixedSubmitButtonlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="center|bottom"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@color/transparent"
android:orientation="vertical"
>
<TextView
android:id="@+id/submit_users_btn"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/textview_border"
android:gravity="center"
android:letterSpacing="0.07"
android:lineSpacingExtra="0sp"
android:text="@string/register_guest_caps"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.Text.RidleyGrotesk.Regular"
android:textColor="#757575"
android:textSize="16sp"
android:textStyle="normal"
/>
</LinearLayout>
</RelativeLayout>

关于android - 如何在协调器布局中将 LinearLayout 附加到屏幕底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58487314/

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