【问题标题】:Expandable scrolling fragment/view over another fragment可扩展的滚动片段/视图在另一个片段上
【发布时间】:2016-11-29 09:37:54
【问题描述】:

我需要制作一个 Android 应用,它的工作方式与最新的谷歌地图类似(你点击一个点,从底部弹出一个视图。你甚至可以将此视图扩展为全屏片段) 不幸的是,我无法复制这种行为。我在 github 上找到了一个提供滚动面板的库。但我不确定它是否是我需要使用的。 有什么想法吗?

【问题讨论】:

  • 您有任何视频/示例来准确展示您想要实现的目标吗?另外,请尝试查看CoordinatorLayout。乍一看,它似乎可以做你想做的事。
  • 我在我的问题中描述了这种行为,但我会制作一个 gif 并在今天晚些时候发布在这里
  • GIF 会很有帮助。请查看链接,看看是否是您想要的。

标签: android listview android-fragments fragment


【解决方案1】:

谷歌设计支持库中有一个名为 BottomSheet 的可用行为,您可以使用它来实现该行为。将此添加到您的 App 模块 gradle 中

compile 'com.android.support:design:23.2.0'

然后在你的xml中添加底部

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">



<android.support.v4.widget.NestedScrollView
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:clipToPadding="true"
    android:background="@android:color/holo_orange_light"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/ipsum"
        android:padding="16dp"
        android:textSize="16sp"/>

</android.support.v4.widget.NestedScrollView>


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

注意 NestedScrollView 是给定的 BottomSheetBehavior

app:layout_behavior="android.support.design.widget.BottomSheetBehavior"

然后是Java文件

private BottomSheetBehavior mBottomSheetBehavior;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View bottomSheet = findViewById( R.id.bottom_sheet );
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
}

然后显示底部工作表使用

mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

并隐藏底部工作表使用

mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

欲了解更多信息,请查看 BottomSheet Example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    相关资源
    最近更新 更多