sách gpt4 ăn đã đi

android - 将顶部内容锚定到 BottomSheet

In lại Tác giả: Walker 123 更新时间:2023-11-29 16:33:47 30 4
mua khóa gpt4 giày 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".social.friends.FriendsListFragment">

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

<>
android:id="@+id/teaser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
app:friendsTeaserState="EMPTY" />


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

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

<>
android:id="@+id/connectFacebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:friendsConnectType="facebook" />

<>
android:id="@+id/connectContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:friendsConnectType="contacts" />

<>
android:id="@+id/share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:friendsConnectType="invite" />


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

解决方案:这是 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)
)
}
})

câu trả lời hay nhất

我的例子是这样的:

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/

30 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress