如何将顶视图折叠成较小尺寸的视图?

2023-12-29

这个问题之前曾以过于宽泛和不清楚的方式提出过here https://stackoverflow.com/q/47053822/878126,所以我使它更加具体,并提供了我所尝试的完整解释和代码。

背景

我需要模仿谷歌日历在顶部有一个视图的方式,它可以动画并下推底部的视图,但它有额外的、不同的行为。我总结了我正在尝试做的 3 个特征:

  1. 按工具栏始终有效,可以切换顶视图的展开/折叠,同时有一个可以更改其旋转的箭头图标。这就像 Google 日历应用程序一样。
  2. 顶视图始终会对齐,就像在 Google 日历应用程序上一样。
  3. 当顶视图折叠时,只需按工具栏即可将其展开。这就像 Google 日历应用程序一样
  4. 当顶视图展开时,滚动底视图将只允许折叠。如果您尝试向另一个方向滚动,则不会发生任何事情,甚至不会滚动到底部视图。这就像 Google 日历应用程序一样
  5. 折叠后,顶视图将替换为较小的视图。这意味着它总是会在底视图上方占据一些空间。这与 Google 日历应用程序不同,因为在日历应用程序上,一旦折叠顶部视图就会完全消失。

Google 日历应用程序如下所示:

在底部视图上滚动也会慢慢隐藏顶部视图:

问题

使用我过去发现的各种解决方案,我仅成功实现了所需行为的一部分:

  1. 工具栏中的一些 UI 是通过其中包含一些视图(包括箭头视图)来完成的。对于手动扩展/折叠我使用setExpanded on the AppBarLayout看法。对于箭头的旋转,我使用了一个侦听器来了解箭头的旋转程度AppBarLayout已调整大小,使用addOnOffsetChangedListener on it.

  2. 通过添加即可轻松完成捕捉snap值转化为layout_scrollFlags的属性CollapsingToolbarLayout。然而,为了让它真正工作良好,没有奇怪的问题(报告here https://issuetracker.google.com/issues/63745189), 我用了这个解决方案 https://stackoverflow.com/a/45338791/878126.

  3. 可以使用我在 #2 上使用的相同代码来阻止滚动时影响顶视图(here https://stackoverflow.com/a/45338791/878126),通过调用setExpandEnabled那里。 当顶视图折叠时,这非常有效。

  4. 与 #3 类似,但遗憾的是,因为它使用setNestedScrollingEnabled,这是两个方向的,只有当顶视图折叠时这才有效。当它展开时,它仍然允许底部视图向上滚动,这与日历应用程序不同。展开时,我需要它只允许折叠,而不允许真正滚动。

这是好的和坏的示范:

  1. 这一点我完全没能做到。我尝试了很多我想过的解决方案,将视图放在带有不同标志的不同位置。

简而言之,我成功地完成了 1-3,但没有成功完成 4-5。

The code

这是当前的代码(也可以作为整个项目使用here https://ufile.io/obvnu) :

滚动活动.kt

class ScrollingActivity : AppCompatActivity(), AppBarTracking {

    private var mNestedView: MyRecyclerView? = null
    private var mAppBarOffset: Int = 0
    private var mAppBarIdle = false
    private var mAppBarMaxOffset: Int = 0

    private var isExpanded: Boolean = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_scrolling)
        val toolbar = findViewById<Toolbar>(R.id.toolbar)
        setSupportActionBar(toolbar)
        mNestedView = findViewById(R.id.nestedView)
        app_bar.addOnOffsetChangedListener({ appBarLayout, verticalOffset ->
            mAppBarOffset = verticalOffset
            val totalScrollRange = appBarLayout.totalScrollRange
            val progress = (-verticalOffset).toFloat() / totalScrollRange
            arrowImageView.rotation = 180 + progress * 180
            isExpanded = verticalOffset == 0;
            mAppBarIdle = mAppBarOffset >= 0 || mAppBarOffset <= mAppBarMaxOffset
            if (mAppBarIdle)
                setExpandAndCollapseEnabled(isExpanded)
        })

        app_bar.post(Runnable { mAppBarMaxOffset = -app_bar.totalScrollRange })

        mNestedView!!.setAppBarTracking(this)
        mNestedView!!.layoutManager = LinearLayoutManager(this)
        mNestedView!!.adapter = object : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
            override fun getItemCount(): Int = 100

            override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
                return object : ViewHolder(LayoutInflater.from(parent.context).inflate(android.R.layout.simple_list_item_1, parent, false)) {}
            }

            override fun onBindViewHolder(holder: ViewHolder, position: Int) {
                (holder.itemView.findViewById<View>(android.R.id.text1) as TextView).text = "item $position"
            }
        }

        expandCollapseButton.setOnClickListener({ v ->
            isExpanded = !isExpanded
            app_bar.setExpanded(isExpanded, true)
        })
    }

    private fun setExpandAndCollapseEnabled(enabled: Boolean) {
        mNestedView!!.isNestedScrollingEnabled = enabled
    }

    override fun isAppBarExpanded(): Boolean = mAppBarOffset == 0
    override fun isAppBarIdle(): Boolean = mAppBarIdle
}

MyRecyclerView.kt

/**A RecyclerView that allows temporary pausing of casuing its scroll to affect appBarLayout, based on https://stackoverflow.com/a/45338791/878126 */
class MyRecyclerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : RecyclerView(context, attrs, defStyle) {
    private var mAppBarTracking: AppBarTracking? = null
    private var mView: View? = null
    private var mTopPos: Int = 0
    private var mLayoutManager: LinearLayoutManager? = null

    interface AppBarTracking {
        fun isAppBarIdle(): Boolean
        fun isAppBarExpanded(): Boolean
    }

    override fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?,
                                         type: Int): Boolean {
        if (type == ViewCompat.TYPE_NON_TOUCH && mAppBarTracking!!.isAppBarIdle()
                && isNestedScrollingEnabled) {
            if (dy > 0) {
                if (mAppBarTracking!!.isAppBarExpanded()) {
                    consumed!![1] = dy
                    return true
                }
            } else {
                mTopPos = mLayoutManager!!.findFirstVisibleItemPosition()
                if (mTopPos == 0) {
                    mView = mLayoutManager!!.findViewByPosition(mTopPos)
                    if (-mView!!.top + dy <= 0) {
                        consumed!![1] = dy - mView!!.top
                        return true
                    }
                }
            }
        }

        val returnValue = super.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow, type)
        if (offsetInWindow != null && !isNestedScrollingEnabled && offsetInWindow[1] != 0)
            offsetInWindow[1] = 0
        return returnValue
    }

    override fun setLayoutManager(layout: RecyclerView.LayoutManager) {
        super.setLayoutManager(layout)
        mLayoutManager = layoutManager as LinearLayoutManager
    }

    fun setAppBarTracking(appBarTracking: AppBarTracking) {
        mAppBarTracking = appBarTracking
    }

}

滚动日历行为.kt

class ScrollingCalendarBehavior(context: Context, attrs: AttributeSet) : AppBarLayout.Behavior(context, attrs) {
    override fun onInterceptTouchEvent(parent: CoordinatorLayout?, child: AppBarLayout?, ev: MotionEvent): Boolean = false
}

活动滚动.xml

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/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" tools:context=".ScrollingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content"
        android:fitsSystemWindows="true" android:stateListAnimator="@null" android:theme="@style/AppTheme.AppBarOverlay"
        app:expanded="false" app:layout_behavior="com.example.user.expandingtopviewtest.ScrollingCalendarBehavior"
        tools:targetApi="lollipop">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout" android:layout_width="match_parent"
            android:layout_height="match_parent" android:fitsSystemWindows="true"
            android:minHeight="?attr/actionBarSize" app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" app:statusBarScrim="?attr/colorPrimaryDark">

            <LinearLayout
                android:layout_width="match_parent" android:layout_height="250dp"
                android:layout_marginTop="?attr/actionBarSize" app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="1.0">

                <TextView
                    android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="10dp"
                    android:paddingRight="10dp" android:text="some large, expanded view"/>
            </LinearLayout>

            <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/AppTheme.PopupOverlay">

                <android.support.constraint.ConstraintLayout
                    android:id="@+id/expandCollapseButton" android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize" android:background="?android:selectableItemBackground"
                    android:clickable="true" android:focusable="true" android:orientation="vertical">

                    <TextView
                        android:id="@+id/titleTextView" android:layout_width="wrap_content"
                        android:layout_height="wrap_content" android:layout_marginBottom="8dp"
                        android:layout_marginLeft="8dp" android:layout_marginStart="8dp" android:ellipsize="end"
                        android:gravity="center" android:maxLines="1" android:text="title"
                        android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
                        android:textColor="@android:color/white" app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintStart_toStartOf="parent"/>

                    <ImageView
                        android:id="@+id/arrowImageView" android:layout_width="wrap_content" android:layout_height="0dp"
                        android:layout_marginLeft="8dp" android:layout_marginStart="8dp"
                        app:layout_constraintBottom_toBottomOf="@+id/titleTextView"
                        app:layout_constraintStart_toEndOf="@+id/titleTextView"
                        app:layout_constraintTop_toTopOf="@+id/titleTextView"
                        app:srcCompat="@android:drawable/arrow_down_float"
                        tools:ignore="ContentDescription,RtlHardcoded"/>

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

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

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

    <com.example.user.expandingtopviewtest.MyRecyclerView
        android:id="@+id/nestedView" android:layout_width="match_parent" android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context=".ScrollingActivity"/>

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

问题

  1. 如何在顶视图展开时阻止滚动,但在滚动时允许折叠?

  2. 如何使顶视图在折叠时替换为较小的视图(并在展开时恢复为大视图),而不是完全消失?


Update

尽管我已经了解了我所询问的基本内容,但当前代码仍然存在 2 个问题(可在 Github 上找到,here https://github.com/Cheticamp/ExpandedTopViewTestUpdate) :

  1. 小视图(您在折叠状态下看到的视图)具有需要对其产生点击效果的内部视图。当使用android:background="?attr/selectableItemBackgroundBorderless"在它们上,并在展开时单击该区域,将在小视图上进行单击。我已经通过将小视图放在不同的工具栏上来处理它,但是点击效果根本没有显示。我已经写过这个here https://github.com/Cheticamp/ExpandedTopViewTestUpdate/issues/1,包括示例项目。

这是修复方法:

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/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" tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content"
        android:fitsSystemWindows="true" android:stateListAnimator="@null" android:theme="@style/AppTheme.AppBarOverlay"
        app:expanded="false" app:layout_behavior="com.example.expandedtopviewtestupdate.ScrollingCalendarBehavior"
        tools:targetApi="lollipop">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout" android:layout_width="match_parent"
            android:layout_height="match_parent" android:clipChildren="false" android:clipToPadding="false"
            android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlways"
            app:statusBarScrim="?attr/colorPrimaryDark">

            <!--large view -->
            <LinearLayout
                android:id="@+id/largeView" android:layout_width="match_parent" android:layout_height="280dp"
                android:layout_marginTop="?attr/actionBarSize" android:orientation="vertical"
                app:layout_collapseMode="parallax" app:layout_collapseParallaxMultiplier="1.0">

                <TextView
                    android:id="@+id/largeTextView" android:layout_width="match_parent"
                    android:layout_height="match_parent" android:layout_gravity="center"
                    android:background="?attr/selectableItemBackgroundBorderless" android:clickable="true"
                    android:focusable="true" android:focusableInTouchMode="false" android:gravity="center"
                    android:text="largeView" android:textSize="14dp" tools:background="?attr/colorPrimary"
                    tools:layout_gravity="top|center_horizontal" tools:layout_height="40dp" tools:layout_width="40dp"
                    tools:text="1"/>

            </LinearLayout>

            <!--top toolbar-->
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/small_view_height" app:contentInsetStart="0dp"
                app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay">

                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent" android:layout_height="wrap_content" android:clickable="true"
                    android:focusable="true">

                    <LinearLayout
                        android:id="@+id/expandCollapseButton" android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:background="?android:selectableItemBackground" android:gravity="center_vertical"
                        android:orientation="horizontal" app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent">

                        <TextView
                            android:id="@+id/titleTextView" android:layout_width="wrap_content"
                            android:layout_height="wrap_content" android:ellipsize="end" android:gravity="center"
                            android:maxLines="1" android:text="title"
                            android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
                            android:textColor="@android:color/white"/>

                        <ImageView
                            android:id="@+id/arrowImageView" android:layout_width="wrap_content"
                            android:layout_height="wrap_content" android:layout_marginLeft="8dp"
                            android:layout_marginStart="8dp" app:srcCompat="@android:drawable/arrow_up_float"
                            tools:ignore="ContentDescription,RtlHardcoded"/>
                    </LinearLayout>

                </android.support.constraint.ConstraintLayout>

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/smallLayoutContainer" android:layout_width="match_parent"
                android:layout_height="wrap_content" android:layout_marginTop="?attr/actionBarSize"
                android:clipChildren="false" android:clipToPadding="false" app:contentInsetStart="0dp"
                app:layout_collapseMode="pin">
                <!--small view-->
                <LinearLayout
                    android:id="@+id/smallLayout" android:layout_width="match_parent"
                    android:layout_height="@dimen/small_view_height" android:clipChildren="false"
                    android:clipToPadding="false" android:orientation="horizontal" tools:background="#ff330000"
                    tools:layout_height="@dimen/small_view_height">

                    <TextView
                        android:id="@+id/smallTextView" android:layout_width="match_parent"
                        android:layout_height="match_parent" android:layout_gravity="center"
                        android:background="?attr/selectableItemBackgroundBorderless" android:clickable="true"
                        android:focusable="true" android:focusableInTouchMode="false" android:gravity="center"
                        android:text="smallView" android:textSize="14dp" tools:background="?attr/colorPrimary"
                        tools:layout_gravity="top|center_horizontal" tools:layout_height="40dp"
                        tools:layout_width="40dp" tools:text="1"/>

                </LinearLayout>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>

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

    <com.example.expandedtopviewtestupdate.MyRecyclerView
        android:id="@+id/nestedView" android:layout_width="match_parent" android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context=".ScrollingActivity"/>

</android.support.design.widget.CoordinatorLayout>
  1. Google 日历允许在工具栏本身上执行向下滚动手势,以触发显示月视图。我已经成功地只在那里添加了点击事件,但没有滚动。它看起来是这样的:

注意:完整更新的项目可用here https://github.com/Cheticamp/ExpandedTopViewTestUpdate.

如何在顶视图展开时阻止滚动,但在滚动时允许折叠?

问题#1: The RecyclerView当应用栏未折叠时,应该根本无法滚动。要解决此问题,请添加enterAlways到滚动标志CollapsingToolbarLayout如下:

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsingToolbarLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:fitsSystemWindows="true"
    app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlways"
    app:statusBarScrim="?attr/colorPrimaryDark">

enterAlways不会导致应用程序栏在关闭时打开,因为您正在抑制该功能,但否则会按预期工作。

问题#2:当应用栏完全展开时,RecyclerView不应允许向上滚动。这恰好是与问题#1 不同的问题。

[更新]要纠正此问题,请修改RecyclerViewRecyclerView尝试向上滚动并且应用栏已完全展开或将在滚动后完全展开(dy) 被消耗。这RecyclerView可以向上滚动,但它从未看到该操作,因为它的行为,SlidingPanelBehavior,消耗卷轴。如果应用栏未完全展开,但在当前滚动消耗后将展开,则该行为通过调用修改强制应用栏完全展开dy并在完全消耗滚动之前调用 super 。 (看SlidingPanelBehavior#onNestedPreScroll())。 (在前面的答案中,修改了 appBar 行为。将行为更改放在RecyclerView是一个更好的选择。)

问题#3:设置嵌套滚动RecyclerView当嵌套滚动已处于所需状态时启用/禁用会导致问题。为了避免这些问题,只有在真正进行更改时才更改嵌套滚动的状态,方法如下:ScrollingActivity:

private void setExpandAndCollapseEnabled(boolean enabled) {
    if (mNestedView.isNestedScrollingEnabled() != enabled) {
        mNestedView.setNestedScrollingEnabled(enabled);
    }
}

这是测试应用程序在进行上述更改后的行为方式:

具有上述更改的更改模块位于帖子末尾。

如何使顶视图在折叠时替换为较小的视图(并在展开时恢复为大视图),而不是完全消失?

[Update]使较小的视图成为其直接子视图CollapsingToolbarLayout所以它是一个兄弟姐妹Toolbar。下面是这种方法的演示。这collapseMode较小视图的设置为pin。较小视图的边距以及工具栏的边距都会调整,以便较小视图紧邻工具栏下方。自从CollapsingToolbarLayout is a FrameLayout、视图堆栈和高度FrameLayout只是成为最高子视图的高度。这种结构将避免插图需要调整的问题以及点击效果丢失的问题。

最后一个问题仍然存在,向下拖动应用栏应该打开它,假设向下拖动较小的视图不应打开应用栏。允许应用栏在拖动时打开是通过以下方式完成的setDragCallback https://developer.android.com/reference/android/support/design/widget/AppBarLayout.Behavior.html#setDragCallback(android.support.design.widget.AppBarLayout.Behavior.DragCallback) of AppBarLayout.Behavior。由于较小的视图已合并到应用程序栏中,因此向下拖动它将打开应用程序栏。为了防止这种情况,一种新的行为称为MyAppBarBehavior附加到应用栏。此行为与中的代码结合使用MainActivity防止拖动较小的视图来打开应用程序栏,但允许拖动工具栏。

活动主文件

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:stateListAnimator="@null"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:expanded="false"
        app:layout_behavior=".MyAppBarBehavior"
        tools:targetApi="lollipop">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlways"
            app:statusBarScrim="?attr/colorPrimaryDark">

            <!--large view -->
            <LinearLayout
                android:id="@+id/largeView"
                android:layout_width="match_parent"
                android:layout_height="280dp"
                android:layout_marginTop="?attr/actionBarSize"
                android:orientation="vertical"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="1.0">

                <TextView
                    android:id="@+id/largeTextView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:focusable="true"
                    android:focusableInTouchMode="false"
                    android:gravity="center"
                    android:text="largeView"
                    android:textSize="14dp"
                    tools:background="?attr/colorPrimary"
                    tools:layout_gravity="top|center_horizontal"
                    tools:layout_height="40dp"
                    tools:layout_width="40dp"
                    tools:text="1" />

            </LinearLayout>

            <!--top toolbar-->
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/small_view_height"
                app:contentInsetStart="0dp"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay">

                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:focusable="true">

                    <LinearLayout
                        android:id="@+id/expandCollapseButton"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:background="?android:selectableItemBackground"
                        android:gravity="center_vertical"
                        android:orientation="horizontal"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent">

                        <TextView
                            android:id="@+id/titleTextView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:ellipsize="end"
                            android:gravity="center"
                            android:maxLines="1"
                            android:text="title"
                            android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
                            android:textColor="@android:color/white" />

                        <ImageView
                            android:id="@+id/arrowImageView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="8dp"
                            android:layout_marginStart="8dp"
                            app:srcCompat="@android:drawable/arrow_up_float"
                            tools:ignore="ContentDescription,RtlHardcoded" />
                    </LinearLayout>

                </android.support.constraint.ConstraintLayout>

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

            <!--small view-->
            <LinearLayout
                android:id="@+id/smallLayout"
                android:layout_width="match_parent"
                android:layout_height="@dimen/small_view_height"
                android:layout_marginTop="?attr/actionBarSize"
                android:clipChildren="false"
                android:clipToPadding="false"
                android:orientation="horizontal"
                app:layout_collapseMode="pin"
                tools:background="#ff330000"
                tools:layout_height="@dimen/small_view_height">

                <TextView
                    android:id="@+id/smallTextView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:focusable="true"
                    android:focusableInTouchMode="false"
                    android:gravity="center"
                    android:text="smallView"
                    android:textSize="14dp"
                    tools:background="?attr/colorPrimary"
                    tools:layout_gravity="top|center_horizontal"
                    tools:layout_height="40dp"
                    tools:layout_width="40dp"
                    tools:text="1" />

            </LinearLayout>
        </android.support.design.widget.CollapsingToolbarLayout>

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

    <com.example.expandedtopviewtestupdate.MyRecyclerView
        android:id="@+id/nestedView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context=".SlidingPanelBehavior" />

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

最后,在addOnOffsetChangedListener添加以下代码以随着应用栏展开和收缩而在较小的视图中淡出/淡出。一旦视图的 alpha 为零(不可见),将其可见性设置为View.INVISIBLE所以无法点击。一旦视图的 alpha 增加到零以上,通过将其可见性设置为使其可见并可单击View.VISIBLE.

mSmallLayout.setAlpha((float) -verticalOffset / totalScrollRange);
// If the small layout is not visible, make it officially invisible so
// it can't receive clicks.
if (alpha == 0) {
    mSmallLayout.setVisibility(View.INVISIBLE);
} else if (mSmallLayout.getVisibility() == View.INVISIBLE) {
    mSmallLayout.setVisibility(View.VISIBLE);
}

结果如下:

以下是包含上述所有更改的新模块。

MainActivity.java

public class MainActivity extends AppCompatActivity
    implements MyRecyclerView.AppBarTracking {
    private MyRecyclerView mNestedView;
    private int mAppBarOffset = 0;
    private boolean mAppBarIdle = true;
    private int mAppBarMaxOffset = 0;
    private AppBarLayout mAppBar;
    private boolean mIsExpanded = false;
    private ImageView mArrowImageView;
    private LinearLayout mSmallLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        LinearLayout expandCollapse;

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = findViewById(R.id.toolbar);
        expandCollapse = findViewById(R.id.expandCollapseButton);
        mArrowImageView = findViewById(R.id.arrowImageView);
        mNestedView = findViewById(R.id.nestedView);
        mAppBar = findViewById(R.id.app_bar);
        mSmallLayout = findViewById(R.id.smallLayout);

        // Log when the small text view is clicked
        findViewById(R.id.smallTextView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "<<<<click small layout");
            }
        });

        // Log when the big text view is clicked.
        findViewById(R.id.largeTextView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "<<<<click big view");
            }
        });

        setSupportActionBar(toolbar);
        ActionBar ab = getSupportActionBar();
        if (ab != null) {
            getSupportActionBar().setDisplayShowTitleEnabled(false);
        }

        mAppBar.post(new Runnable() {
            @Override
            public void run() {
                mAppBarMaxOffset = -mAppBar.getTotalScrollRange();

                CoordinatorLayout.LayoutParams lp =
                    (CoordinatorLayout.LayoutParams) mAppBar.getLayoutParams();
                MyAppBarBehavior behavior = (MyAppBarBehavior) lp.getBehavior();
                // Only allow drag-to-open if the drag touch is on the toolbar.
                // Once open, all drags are allowed.
                if (behavior != null) {
                    behavior.setCanOpenBottom(findViewById(R.id.toolbar).getHeight());
                }
            }
        });

        mNestedView.setAppBarTracking(this);
        mNestedView.setLayoutManager(new LinearLayoutManager(this));
        mNestedView.setAdapter(new RecyclerView.Adapter<RecyclerView.ViewHolder>() {
            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                return new ViewHolder(
                    LayoutInflater.from(parent.getContext())
                        .inflate(android.R.layout.simple_list_item_1, parent, false));
            }

            @SuppressLint("SetTextI18n")
            @Override
            public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
                ((TextView) holder.itemView.findViewById(android.R.id.text1))
                    .setText("Item " + position);
            }

            @Override
            public int getItemCount() {
                return 200;
            }

            class ViewHolder extends RecyclerView.ViewHolder {
                public ViewHolder(View view) {
                    super(view);
                }
            }
        });

        mAppBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                mAppBarOffset = verticalOffset;
                int totalScrollRange = appBarLayout.getTotalScrollRange();
                float progress = (float) (-verticalOffset) / (float) totalScrollRange;
                mArrowImageView.setRotation(-progress * 180);
                mIsExpanded = verticalOffset == 0;
                mAppBarIdle = mAppBarOffset >= 0 || mAppBarOffset <= mAppBarMaxOffset;
                float alpha = (float) -verticalOffset / totalScrollRange;
                mSmallLayout.setAlpha(alpha);

                // If the small layout is not visible, make it officially invisible so
                // it can't receive clicks.
                if (alpha == 0) {
                    mSmallLayout.setVisibility(View.INVISIBLE);
                } else if (mSmallLayout.getVisibility() == View.INVISIBLE) {
                    mSmallLayout.setVisibility(View.VISIBLE);
                }
            }
        });

        expandCollapse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setExpandAndCollapseEnabled(true);
                if (mIsExpanded) {
                    setExpandAndCollapseEnabled(false);
                }
                mIsExpanded = !mIsExpanded;
                mNestedView.stopScroll();
                mAppBar.setExpanded(mIsExpanded, true);
            }
        });
    }

    private void setExpandAndCollapseEnabled(boolean enabled) {
        if (mNestedView.isNestedScrollingEnabled() != enabled) {
            mNestedView.setNestedScrollingEnabled(enabled);
        }
    }

    @Override
    public boolean isAppBarExpanded() {
        return mAppBarOffset == 0;
    }

    @Override
    public boolean isAppBarIdle() {
        return mAppBarIdle;
    }

    private static final String TAG = "MainActivity";
}

SlidingPanelBehavior.java

public class SlidingPanelBehavior extends AppBarLayout.ScrollingViewBehavior {
    private AppBarLayout mAppBar;

    public SlidingPanelBehavior() {
        super();
    }

    public SlidingPanelBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(final CoordinatorLayout parent, View child, View dependency) {
        if (mAppBar == null && dependency instanceof AppBarLayout) {
            // Capture our appbar for later use.
            mAppBar = (AppBarLayout) dependency;
        }
        return dependency instanceof AppBarLayout;
    }

    @Override
    public boolean onInterceptTouchEvent(CoordinatorLayout parent, View child, MotionEvent event) {
        int action = event.getAction();

        if (event.getAction() != MotionEvent.ACTION_DOWN) { // Only want "down" events
            return false;
        }
        if (getAppBarLayoutOffset(mAppBar) == -mAppBar.getTotalScrollRange()) {
            // When appbar is collapsed, don't let it open through nested scrolling.
            setNestedScrollingEnabledWithTest((NestedScrollingChild2) child, false);
        } else {
            // Appbar is partially to fully expanded. Set nested scrolling enabled to activate
            // the methods within this behavior.
            setNestedScrollingEnabledWithTest((NestedScrollingChild2) child, true);
        }
        return false;
    }

    @Override
    public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child,
                                       @NonNull View directTargetChild, @NonNull View target,
                                       int axes, int type) {
        //noinspection RedundantCast
        return ((NestedScrollingChild2) child).isNestedScrollingEnabled();
    }

    @Override
    public void onNestedPreScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child,
                                  @NonNull View target, int dx, int dy, @NonNull int[] consumed,
                                  int type) {
        // How many pixels we must scroll to fully expand the appbar. This value is <= 0.
        final int appBarOffset = getAppBarLayoutOffset(mAppBar);

        // Check to see if this scroll will expand the appbar 100% or collapse it fully.
        if (dy <= appBarOffset) {
            // Scroll by the amount that will fully expand the appbar and dispose of the rest (dy).
            super.onNestedPreScroll(coordinatorLayout, mAppBar, target, dx,
                                    appBarOffset, consumed, type);
            consumed[1] += dy;
        } else if (dy >= (mAppBar.getTotalScrollRange() + appBarOffset)) {
            // This scroll will collapse the appbar. Collapse it and dispose of the rest.
            super.onNestedPreScroll(coordinatorLayout, mAppBar, target, dx,
                                    mAppBar.getTotalScrollRange() + appBarOffset,
                                    consumed, type);
            consumed[1] += dy;
        } else {
            // This scroll will leave the appbar partially open. Just do normal stuff.
            super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
        }
    }

    /**
     * {@code onNestedPreFling()} is overriden to address a nested scrolling defect that was
     * introduced in API 26. This method prevent the appbar from misbehaving when scrolled/flung.
     * <p>
     * Refer to <a href="https://issuetracker.google.com/issues/65448468"  target="_blank">"Bug in design support library"</a>
     */

    @Override
    public boolean onNestedPreFling(@NonNull CoordinatorLayout coordinatorLayout,
                                    @NonNull View child, @NonNull View target,
                                    float velocityX, float velocityY) {
        //noinspection RedundantCast
        if (((NestedScrollingChild2) child).isNestedScrollingEnabled()) {
            // Just stop the nested fling and let the appbar settle into place.
            ((NestedScrollingChild2) child).stopNestedScroll(ViewCompat.TYPE_NON_TOUCH);
            return true;
        }
        return super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY);
    }

    private static int getAppBarLayoutOffset(AppBarLayout appBar) {
        final CoordinatorLayout.Behavior behavior =
            ((CoordinatorLayout.LayoutParams) appBar.getLayoutParams()).getBehavior();
        if (behavior instanceof AppBarLayout.Behavior) {
            return ((AppBarLayout.Behavior) behavior).getTopAndBottomOffset();
        }
        return 0;
    }

    // Something goes amiss when the flag it set to its current value, so only call
    // setNestedScrollingEnabled() if it will result in a change.
    private void setNestedScrollingEnabledWithTest(NestedScrollingChild2 child, boolean enabled) {
        if (child.isNestedScrollingEnabled() != enabled) {
            child.setNestedScrollingEnabled(enabled);
        }
    }

    @SuppressWarnings("unused")
    private static final String TAG = "SlidingPanelBehavior";
}

MyRecyclerView.kt

/**A RecyclerView that allows temporary pausing of casuing its scroll to affect appBarLayout, based on https://stackoverflow.com/a/45338791/878126 */
class MyRecyclerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : RecyclerView(context, attrs, defStyle) {
    private var mAppBarTracking: AppBarTracking? = null
    private var mView: View? = null
    private var mTopPos: Int = 0
    private var mLayoutManager: LinearLayoutManager? = null

    interface AppBarTracking {
        fun isAppBarIdle(): Boolean
        fun isAppBarExpanded(): Boolean
    }

    override fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?, type: Int): Boolean {
        if (type == ViewCompat.TYPE_NON_TOUCH && mAppBarTracking!!.isAppBarIdle()
                && isNestedScrollingEnabled) {
            if (dy > 0) {
                if (mAppBarTracking!!.isAppBarExpanded()) {
                    consumed!![1] = dy
                    return true
                }
            } else {
                mTopPos = mLayoutManager!!.findFirstVisibleItemPosition()
                if (mTopPos == 0) {
                    mView = mLayoutManager!!.findViewByPosition(mTopPos)
                    if (-mView!!.top + dy <= 0) {
                        consumed!![1] = dy - mView!!.top
                        return true
                    }
                }
            }
        }
        if (dy < 0 && type == ViewCompat.TYPE_TOUCH && mAppBarTracking!!.isAppBarExpanded()) {
            consumed!![1] = dy
            return true
        }

        val returnValue = super.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow, type)
        if (offsetInWindow != null && !isNestedScrollingEnabled && offsetInWindow[1] != 0)
            offsetInWindow[1] = 0
        return returnValue
    }

    override fun setLayoutManager(layout: RecyclerView.LayoutManager) {
        super.setLayoutManager(layout)
        mLayoutManager = layoutManager as LinearLayoutManager
    }

    fun setAppBarTracking(appBarTracking: AppBarTracking) {
        mAppBarTracking = appBarTracking
    }

    override fun fling(velocityX: Int, velocityY: Int): Boolean {
        var velocityY = velocityY
        if (!mAppBarTracking!!.isAppBarIdle()) {
            val vc = ViewConfiguration.get(context)
            velocityY = if (velocityY < 0) -vc.scaledMinimumFlingVelocity
            else vc.scaledMinimumFlingVelocity
        }

        return super.fling(velocityX, velocityY)
    }
}

MyAppBarBehavior.java

/**
 * Attach this behavior to AppBarLayout to disable the bottom portion of a closed appBar
 * so it cannot be touched to open the appBar. This behavior is helpful if there is some
 * portion of the appBar that displays when the appBar is closed, but should not open the appBar
 * when the appBar is closed.
 */
public class MyAppBarBehavior extends AppBarLayout.Behavior {

    // Touch above this y-axis value can open the appBar.
    private int mCanOpenBottom;

    // Determines if the appBar can be dragged open or not via direct touch on the appBar.
    private boolean mCanDrag = true;

    @SuppressWarnings("unused")
    public MyAppBarBehavior() {
        init();
    }

    @SuppressWarnings("unused")
    public MyAppBarBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        setDragCallback(new AppBarLayout.Behavior.DragCallback() {
            @Override
            public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
                return mCanDrag;
            }
        });
    }

    @Override
    public boolean onInterceptTouchEvent(CoordinatorLayout parent,
                                         AppBarLayout child,
                                         MotionEvent event) {

        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            // If appBar is closed. Only allow scrolling in defined area.
            if (child.getTop() <= -child.getTotalScrollRange()) {
                mCanDrag = event.getY() < mCanOpenBottom;
            }
        }
        return super.onInterceptTouchEvent(parent, child, event);
    }

    public void setCanOpenBottom(int bottom) {
        mCanOpenBottom = bottom;
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将顶视图折叠成较小尺寸的视图? 的相关文章

  • 添加监听器与设置监听器

    添加监听器和设置监听器有什么区别 e g addTextChangedListener textWatcher setOnClickListener clickListener Answer 在 aioobe 的回答之后 我在我的项目中对此
  • 使用缩略图作为毕加索的占位符

    从用户体验的角度来看 首先向用户显示缩略图 直到真实图像完成加载 然后向他显示 这会很棒 但是Picasso https github com square picasso仅使用资源文件作为占位符 例如 Picasso with conte
  • 如何调试使用maven构建的android应用程序

    我目前正在尝试从 Eclipse 调试我的设备上的 Android 应用程序 设备已添加 我可以在控制台和 Eclipse 中看到它 控制台 Windows adb devices List of devices attached 0019
  • Eddystone Beacon 中广播的 MAC ID 会改变吗?

    我将描述我的设置 我制作了一个模拟 Eddystone 信标的 Android 应用程序 我能够使用 PlayStore 中的 Beacon Toy 应用程序检测手机上的 Eddystone 信标 但问题是 自上次检查以来 显示的 MAC
  • 如何对齐文本和图标可组合项,以便即使文本溢出后它们也能保持在一起?

    我有一个文本和一个图标可组合项 我希望图标粘在可组合项的右侧 这是我的代码 Row verticalAlignment Alignment CenterVertically horizontalArrangement Arrangement
  • 如何在谷歌地图中使用latlng字符串数组绘制多边形

    在我的应用程序中 我有包含 imagview 的 recyclerview 并且该 imageview 通过使用我存储在 sqlite 中的坐标包含静态地图图像 当我单击该图像时 我将该字符串数组格式的坐标传递给其他地图活动 然后使用该字符
  • 旧 Android SDK 版本上的 java.lang.NoClassDefFoundError

    我在 Google Play 上发布了我的应用程序的一个版本 今天早上醒来时发现了一些不满意的客户 该应用程序的最新版本集成了对蓝牙低功耗 BTLE 心率监测器的支持 该应用程序在 Android 4 3 和 4 4 上运行良好 但在 4
  • 为什么Volley的onResponse没有被调用

    我正在通过 Volley 获取 json 数据 我遇到的问题 那是凌空的onResponse从未被调用 因此不会解析和显示数据 JSON 数据示例 title This is a sample text title title cat or
  • 如何知道 TTS 何时完成?

    我正在 Android 上实现交互式语音响应应用程序 我想知道如何确定何时tts speak 函数已完成通话 因此我可以调用我的语音识别器函数 public class TTSActivity extends Activity implem
  • Android 时间选择器在分钟滚动时自动更改小时

    例如 当我在 TimePicker 上滚动分钟时 在将分钟滚动到 59 后 小时会自动滚动到 7 因此新时间将为 07 59 同样的方式 如果我有 07 59 并且我将分钟滚动到 00 小时将自动滚动到 8 所以时间将是 08 00 此逻辑
  • 某些设备上的启动画面扭曲

    我在修复 Android 上的启动画面扭曲问题时遇到问题 我正在使用 React Native 请注意 这种情况仅发生在某些设备上 例如 我有一台 Android 版本为 4 2 2 的三星 启动画面不扭曲 而 Android 版本为 8
  • 使用 Backstack 时 TabLayout ViewPager 未加载 [重复]

    这个问题在这里已经有答案了 我在一个片段中使用 TabLayout 和 viewPager 在选项卡下方的两个片段之间切换 当我单击下部片段之一内的 FAB 时 我会加载一个新片段 用于输入 但是 当我按 后退 按钮时 TabLayout
  • 使用 Android Exoplayer 调整 Dash 流音量

    我正在尝试设置一个搜索栏来控制 exoplayer 流式破折号实例的级别 我正在使用的设置是演示项目的修改版本 并且无法确定我应该尝试影响搜索栏输出的哪个元素 即如何正确使用 MSG SET VOLUME 等 任何意见将不胜感激 我正在寻找
  • logcat 信息出现在 Android Studio 的“运行”选项卡中

    我的 android studio 运行选项卡很简单 然后它变得更难并给我更多信息 例如 logcat 中的信息 如何禁用或删除第二张图片中出现的更多信息并返回到第一张图片中的第一个外观 我只需要正在运行的 flutter 应用程序的日志输
  • 找出该月第一个星期日/星期一等的日期

    我想在java中检测每个月第一周 第二周的第一个星期日 星期一的日期 我怎样才能实现它 我已经检查了 java 中的 Calendar 类和 Date 类 但无法找到解决方案 所以请帮助我解决这个问题 Calendar calendar C
  • Android:禁用 1.5 纸杯蛋糕动画过渡

    长话短说 如何禁用活动之间的屏幕转换 如果您愿意的话 我们实现了自己的选项卡处理程序 现在它正在选项卡之间进行转换 这看起来很俗气 谢谢 Chris See android content Intent FLAG ACTIVITY NO A
  • 协程中未捕获异常

    我似乎无法在协程中完成错误处理 我读了很多文章并且异常处理文档 https kotlinlang org docs reference coroutines exception handling html exception propaga
  • 如何以编程方式设置带有密码的屏幕锁定?

    有没有人可以帮我设置密码以锁定屏幕 谢谢 在您的应用程序中使用此代码 它对我有用 DevicePolicyManager devicePolicyManager DevicePolicyManager getSystemService Co
  • 使 autocompletetextview 看起来像 edittext

    我正在使用 AutoCompleteTextView Roboto 自动完成文本视图 https github com johnkil Android RobotoTextView blob master robototextview sr
  • 什么是 Android DecorView?

    http developer android com reference android view Window html getDecorView http developer android com reference android

随机推荐

  • Pyspark:自定义窗口函数

    我目前正在尝试提取 PySpark 数据框中连续出现的一系列事件 并对它们进行排序 排名 如下所示 为了方便起见 我已通过以下方式对初始数据框进行了排序 user id and timestamp df ini user id timest
  • 移位是 O(1) 还是 O(n)?

    是否轮班操作O 1 or O n 计算机通常需要更多的操作来移动 31 位而不是移动 1 位 这是否有意义 或者说这是否有意义操作次数换档所需的是constant不管我们需要转移多少地方 PS 想知道是否hardware是一个合适的标签 某
  • 使用 AWS amplify 和 graphql 创建新用户时出现“未经授权”错误

    所以我认为这个问题来自于我不太理解 AWS cognito 用户池和 graphql 模式中的身份验证规则之间的关系 当我运行下面的代码时 我收到消息 未授权访问 User 类型上的 createUser import React from
  • 从模板中获取 Django 表单小部件的类型

    我正在迭代表单的字段 对于某些字段 我想要稍微不同的布局 需要更改 HTML 为了准确地做到这一点 我只需要知道小部件类型 它的类名或类似的名称 在标准 python 中 这很容易 field field widget class name
  • AS3中dispatchEvent()可以带参数吗?

    看这个例子 addEventListener myEventType myFunction argument function myFunction args String Function return function evt Even
  • 使用 Json.NET 读取大整数

    我有一些带有巨大整数的 json 大约有几百位数字 我想将它们解析为 BouncyCastle 的BigInteger https github com onovotny BouncyCastle PCL blob pcl crypto s
  • 如何在 Mac Os X 上将用户添加到 apache 组?

    我实际上正在尝试在我的 MacBook Pro Mac OS X 10 6 上运行 Symfony2 当我通过 apache 启动应用程序时 所有缓存和日志文件都是由 www www 用户 组创建的 但是 我已经必须使用我自己的用户在 CL
  • 使用 rvest 跟随带有相对路径的“下一个”链接

    我正在使用rvest从页面中抓取信息的包http www radiolab org series podcasts http www radiolab org series podcasts 抓取第一页后 我想点击底部的 下一步 链接 抓取
  • 可以将PreparedStatement.addBatch()用于SELECT查询吗?

    想象一下 我有 100 个 SELECT 查询 它们因一个输入而异 可以使用PreparedStatement 作为该值 我在网上看到的所有文档都是关于批量插入 更新 删除的 我从未见过用于 select 语句的批处理 这可以做到吗 如果是
  • 有哪些好的实体框架替代品[关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我现在正在使用实体框架 并且经常需要编写内联sql 因为实体框架不支持全文搜索和其他功能 是否有一个 ORM 具有许多支持高级查询的功能
  • Wix 和 .NET Framework(先决条件)

    当客户端计算机上尚未安装所需的 NET Framework 时 如何让 Wix 包下载该包 我已经有条件检查已安装的 NET 版本 但我不确定如何在找不到时下载并安装它 ClickOnce 通过检查属性页中的先决条件自动执行此操作 由于一些
  • android-viewflipper 的简单淡出和淡入动画

    我是android新手 对android动画了解不多 我有一个取景器 我想在其中的图像之间制作动画 这是代码 runnable new Runnable public void run handler postDelayed runnabl
  • Oracle,向字符串(不是数字)添加前导零

    我正在使用 Oracle 工作空间是 TOAD 我需要将字符串设置为短接 10 个字符 然后添加前导零以使它们全部为 10 位数字字符串 例如 如果我有一个像这样的字符串 12H89 需要是 0000012H89 或者 1234 变为 00
  • C++中**是什么意思? [复制]

    这个问题在这里已经有答案了 例如 bool insertInFront IntElement head int data IntElement newElem new IntElement if newElem return false n
  • Google 通讯录 api (gdata) 同步低分辨率照片

    我正在使用 google 联系人 api gdata 在 google 联系人中设置联系人的照片 我正在使用 fiddler 我看到请求是根据Google 通讯录示例 https developers google com google a
  • Angular Spectator setInput 不适用于非字符串输入

    我已经成功地将我的项目转换为使用 Jest 代替 Karma Jasmine 并且我有很多测试运行得很好 我正在尝试使用 Spectator 5 2 1 进行一个非常简单的测试 但它不起作用 我正在尝试测试使用 mat table 呈现表格
  • Rails 路由的 API 版本控制

    我正在尝试像 Stripe 那样对我的 API 进行版本控制 下面给出的最新 API 版本是 2 api users返回 301 api v2 users api v1 users返回版本 1 的 200 个用户索引 api v3 user
  • 多条件IF语句

    我有一个包含多个条件的 if 语句 但我似乎无法正确执行 if ISSET SESSION status SESSION username qqqqq ISSET SESSION status SESSION company wwwwww
  • Kotlin 中通过反射获取 Enum 值

    您将如何用 Kotlin 重写以下 Java 代码 SuppressWarnings unchecked rawtypes static Object getEnumValue String enumClassName String enu
  • 如何将顶视图折叠成较小尺寸的视图?

    这个问题之前曾以过于宽泛和不清楚的方式提出过here https stackoverflow com q 47053822 878126 所以我使它更加具体 并提供了我所尝试的完整解释和代码 背景 我需要模仿谷歌日历在顶部有一个视图的方式