如果我使用 Modal BottomSheetFragment 如何添加 BottomSheetBehavior ?
var bottomSheetBehaviorCallback =
object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, slideOffset: Float) {
Log.d(Constants.LOG_INFO, "on slide")
}
override fun onStateChanged(bottomSheet: View, newState: Int) {
Log.d(Constants.LOG_INFO, "onStateChanged")
}
}
val detailView = StationDetailFragment.newInstance(selectedStationID, "")
detailView.show(fragmentManager, "detailView")
Run Code Online (Sandbox Code Playgroud)
此时视图尚未创建
我更改了代码并添加了覆盖 setupDialog 。但我仍然没有得到回调工作
override fun setupDialog(dialog: Dialog?, style: Int) {
val contentView = View.inflate(context, R.layout.fragment_station_detail, null)
dialog!!.setContentView(contentView)
val layoutParams = (contentView.parent as View).layoutParams as CoordinatorLayout.LayoutParams
val behavior = layoutParams.behavior
if (behavior != null && behavior is BottomSheetBehavior<*>) …Run Code Online (Sandbox Code Playgroud) 我的 recyclerview 的项目是动态加载的。底部的 UI 是一个小型音乐播放器。我想在音乐播放器用户界面上方显示回收视图。但目前,音乐播放器 UI 隐藏了 recyclerview 的最后一个元素。音乐播放器的用户界面是动态隐藏/显示的。你能告诉我如何在不被底部 UI(音乐播放器)遮挡的情况下显示 recyclerview 的元素吗?这是我的布局
<?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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:fitsSystemWindows="true"
android:scaleType="fitCenter"
android:transitionName="@string/transition_album_cover"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<FrameLayout
android:id="@+id/bottom_ui_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_behavior="@string/bottom_sheet_behavior">
<include layout="@layout/music_player_ui" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) user-interface android android-recyclerview android-coordinatorlayout bottom-sheet
我在使用nestedscrollview拖动bottomsheet时遇到问题。
有没有办法将视图设置为 BottomSheet 的可拖动部分?
我正在尝试创建与 Material.io 底部工作表可用的类似功能,但使用 jQuery。
我发现为 React 编写的类似内容有一个很好的图像可以解释。 React 可滑动底板
我从一些 jQuery“触摸”模块开始,但发现@roko-c-buljan使用纯 jQuery 有一个很好的起始方法(如何创建可拖动的菜单 div(桌面和移动设备))。
我尝试使用该示例作为从底部而不是顶部开始工作的起点,同时也让它优雅地对齐 - 就像在 React 图像中一样,但在两个不同的级别:距离底部 200px,并且也在底部对齐顶部 - 使用相同的过渡效果继续移动到相同方向的下一个捕捉点。
我基本上正在寻找使用具有触摸功能的 jQuery 的 Material.io 底部工作表设计。
在遇到许多障碍之后,我目前正处于代码中,并希望这比我想象的要接近得多。
请注意,此代码仅在浏览器中使用触摸模式时运行
$(document).ready(function () {
var $MB = $('#menu_btn'),
$M = $('#menu'),
bheight = $(".container-fluid").height(),
startBottom,
startAtY = 10,
endAtY = bheight-10,
clickedAtY,
clickEventType = document.ontouchstart !== null ? 'mousedown' : 'touchstart',
moveEventType = document.ontouchmove !== null ? 'mousemove' : 'touchmove' ,
endEventType = document.ontouchend …Run Code Online (Sandbox Code Playgroud)我试图在点击侦听器中使用底部工作表,但我在这一行收到错误。
BottomSheetFragment.show(getSupportFragmentManager())
无法解析方法“show(?, java.lang.String)”无法解析方法“getSupportFragmentManager()”
我想在片段类中使用底部工作表。
SubCategoryDetailFragment.java
public class SubCategoryDetailFragment extends Fragment {
TextView txtv_sort;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.fragment_sub_category_detail, container, false);
toolbar = ((MainActivity) getActivity()).findViewById(R.id.toolbar);
toggle = ((MainActivity) getActivity()).getToggle();
shimmerContainer = view.findViewById(R.id.shimmer_view_container);
recyclerView_subcatDetail = view.findViewById(R.id.recycler_view_subCategoryDetail);
txtv_sort = view.findViewById(R.id.txtv_sort);
toggle.setDrawerIndicatorEnabled(false);
toggle.setHomeAsUpIndicator(R.drawable.back);
toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
txtv_sort.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag());
}
});
return view; …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种在状态栏后面绘制 BottomSheetDialogFragment 的解决方案。我尝试覆盖样式:
<style name="BaseBottomSheetDialog" parent="@style/Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="bottomSheetStyle">@style/BottomSheet</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但没有任何效果。我的父布局是fitSystemWindows="true"
编辑:我忘了提及我的 BottomSheetDialogFragment 已完全展开并且MATCH_PARENT. 也许有不同的灵魂可以在片段上获得底部工作表行为,而无需从 BottomSheetDialogFragment 扩展。
这是我使用的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top|center_horizontal"
android:background="@color/white"
android:gravity="top|center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/provisioningTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Phone Number" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我创建对话框的类:
open class DialogProvisioningData : BottomSheetDialog {
constructor(context: Context) : super(context)
private lateinit var mBehavior: BottomSheetBehavior<FrameLayout>
override fun setContentView(view: View) {
super.setContentView(view)
val bottomSheet = window.decorView.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout
mBehavior = BottomSheetBehavior.from(bottomSheet)
mBehavior.peekHeight = Resources.getSystem().getDisplayMetrics().heightPixels
mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
}
override fun onStart() {
super.onStart()
mBehavior.peekHeight = Resources.getSystem().getDisplayMetrics().heightPixels
mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
}
companion object {
fun newInstance(context: Context): DialogProvisioningData {
val …Run Code Online (Sandbox Code Playgroud) 我正在尝试做这样的事情,根据列表内容创建一个下拉列表。我的列表看起来像这样,
[
{
id: val,
displayName: Enter value,
type: string,
value: "any"
},
{
id: si,
displayName: Source,
type: list,
value: [
MO
],
data: [
{id: 1, displayId: MO},
{id: 2, displayId: AO},
{id: 3, displayId: OffNet}
]
}
]
Run Code Online (Sandbox Code Playgroud)
目前有 2 个条目。将包含这些选项(输入值和源)的下拉列表显示为 2 个下拉列表条目
如果选择“输入值”,则应在其旁边显示一个文本框,因为它具有字符串类型。如果选择下拉列表中的“源”选项,则包含这些条目(MO、AO、Offnet)的另一个下拉列表应作为下拉值显示,因为它具有列表类型。
根据第一个下拉列表的选择,应选择要显示的小部件(文本框或另一个下拉列表)。
我有这样的代码,它将执行必要的操作,但这里将整个页面作为容器,每当选项更改时,都会调用 setState,它会重建构建方法,但我想在底表中实现相同的操作,在那里我不知道管理状态,即一旦下拉列表中的选项发生变化,我希望底表能够用数据重建。
代码:
import 'package:flutter/material.dart';
void main() {
runApp(DropdownExample());
}
class DropdownExample extends StatefulWidget {
@override
_DropdownExampleState createState() => _DropdownExampleState();
}
class _DropdownExampleState extends State<DropdownExample> {
String type;
int optionId;
final items …Run Code Online (Sandbox Code Playgroud) ModalBottomSheet 自动在下层屏幕上渲染阴影或阴影。
在showModalBottomSheet方法中将背景颜色设置为透明只会影响包含子窗口小部件的区域。
它不会删除模态下的阴影。
我可以删除或更改阴影的不透明度吗?
我试图在应用程序启动时自动在 flutter 中显示bottom sheeet,但它出现错误。仅当我使用单击事件实例化它时,它才适用于我。但我怎样才能在屏幕启动时弹出它呢?
@override
Widget build(BuildContext context) {
showModalBottomSheet(context: context, builder: (BuildContext context) {
return Container();
});
Run Code Online (Sandbox Code Playgroud) bottom-sheet ×10
android ×6
flutter ×3
dart ×2
dialog ×1
fragment ×1
javascript ×1
jquery ×1
kotlin ×1