gpt4 book ai didi

android - 将顶部内容锚定到 BottomSheet

转载 作者:行者123 更新时间:2023-11-29 16:33:47 28 4
gpt4 key购买 nike

我有一个 FrameLayout (teaserContainer) 和 BottomSheet (invitesContainer)。 FrameLayout 位于 BottomSheet 之外(和上方)。我希望 FrameLayout 收缩并跟随 BottomSheet,因此 FremeLayout 在 BottomSheet 展开时折叠。

现在发生的事情是 FrameLayout 占据了整个页面,因为它的 android:layout_height="match_parent" 但如果我将它设置为 android:layout_height="wrap_content" 它显示在 BottomSheet 的后面,并且像 FAB 一样垂直居中。

我希望当 BottomSheet (invitesContainer) 完全展开时,FrameLayout (teaserContainer) 应该占据屏幕的其余部分,直到工具栏。

所有将 View 锚定到 BottomSheet 的示例都涉及 FAB,因此这里对我没有任何帮助。

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".social.friends.FriendsListFragment">

<FrameLayout
android:id="@+id/teaserContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fitsSystemWindows="true"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
app:layout_anchor="@+id/invitesContainer"
app:layout_anchorGravity="top">

<com.myapp.android.common.social.friends.views.FriendsTeaser
android:id="@+id/teaser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
app:friendsTeaserState="EMPTY" />
</FrameLayout>

<LinearLayout
android:id="@+id/invitesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.1"
android:background="@color/body" />

<com.myapp.android.common.social.friends.views.FriendsConnectItem
android:id="@+id/connectFacebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:friendsConnectType="facebook" />

<com.myapp.android.common.social.friends.views.FriendsConnectItem
android:id="@+id/connectContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:friendsConnectType="contacts" />

<com.myapp.android.common.social.friends.views.FriendsConnectItem
android:id="@+id/share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:friendsConnectType="invite" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

-------------------------------------------- ---------------------------------------------- --------------

解决方案:这是 Vadim 建议的 Kotlin 版本

BottomSheetBehavior.from(invitesContainer).setBottomSheetCallback(object :
BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
}

override fun onSlide(bottomSheet: View, slideOffset: Float) {
val currentHeight = teaserContainer.height - bottomSheet.height
val bottomSheetShiftDown = currentHeight - bottomSheet.top
teaserContainer.setPadding(
0,
0,
0,
(bottomSheet.height + bottomSheetShiftDown)
)
}
})

最佳答案

我的例子是这样的:

public void onSlide(@NonNull View bottomSheet, float slideOffset) {
int currentHeight = teaserContainer.getHeight() - bottomSheet.getHeight();
int bottomSheetShiftDown = currentHeight - bottomSheet.getTop();
rootContainer.setPadding(
0,
0,
0,
(mBottomSheet.getPeekHeight() + bottomSheetShiftDown));
}

mBottomSheet - BottomSheetBehavior mBottomSheet = BottomSheetBehavior.from(invitesContainer);

因此,当您将它拉下来时,这将添加/删除您的 teaserContainer 的填充。

关于android - 将顶部内容锚定到 BottomSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53187969/

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