我的布局如下
滚动时,我需要先让 Layout2 消失,然后再消失 Layout1。例如看下面的 gif 中间视图先消失然后顶视图消失。我怀疑我需要一些自定义行为代码,但不知道从哪里开始。
这是我当前的 xml
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.chamoda.coordinatelayoutdemo.ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="180dp"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="@color/colorAccent"
app:layout_scrollFlags="scroll" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll" >
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.chamoda.coordinatelayoutdemo.ScrollingActivity"
tools:showIn="@layout/activity_scrolling">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:text="@string/large_text" />
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
如何使用坐标布局存档该动画?
我正在尝试在不换行的情况下将值打印到控制台。例如,如果我尝试以下
IO.puts("Hello ")
IO.puts("World")
Run Code Online (Sandbox Code Playgroud)
我希望它能打印一行
Hello World
Run Code Online (Sandbox Code Playgroud)
编辑:我需要做的是打印而不带尾随 CR
假设x是0到1之间的实数
如果n = 2,则有两个分数范围0到0.5和0.5到1
如果n = 3,则存在三个分数范围0至0.33,0.33至0.66和0.66至1
我想知道最有效的算法,它可以告诉x属于哪一部分.
如果x = 0.2且n = 3,则x属于第一个分数,因此index为0
如果x = 0.4且n = 3,则x属于第二个分数,因此index为1
这是具有O(N)复杂度的python 3代码.
def index(x, n):
for i in range(0, n):
if i/n <= x and x <= (i + 1)/n:
return i
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更好的算法可能会有恒定的时间?
编辑:我之前没有明确说过,但0和1都是x的合法值,当x = 1时,结果应为n - 1