Created
November 16, 2015 23:27
-
-
Save woshidan/ffcc5d546fd545558b3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final NestedScrollView mParentNestedScrollView = (NestedScrollView) findViewById(R.id.scrollView); | |
Button button = (Button) findViewById(R.id.button); | |
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); | |
LinearLayoutManager layoutManager = new LinearLayoutManager(this); | |
recyclerView.setLayoutManager(layoutManager); | |
Observable.interval(50, TimeUnit.MILLISECONDS) | |
.subscribeOn(AndroidSchedulers.mainThread()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(new rx.Observer<Long>() { | |
@Override | |
public void onCompleted() { | |
} | |
@Override | |
public void onError(Throwable e) { | |
} | |
@Override | |
public void onNext(Long aLong) { | |
// scrollXの値によってイベントを起こす.. | |
getSupportActionBar().setSubtitle(mParentNestedScrollView.getScrollY() + "px"); | |
// Toast.makeText(MainActivity.this, mParentNestedScrollView.getScrollY() + "px", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/scrollView" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
tools:context=".MainActivity"> | |
<LinearLayout | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
> | |
<TextView | |
android:overScrollMode="always" | |
android:id="@+id/textView0" | |
android:layout_width="match_parent" | |
android:layout_height="100dp" | |
android:background="#ccc" | |
/> | |
<Button | |
android:id="@+id/button" | |
android:layout_height="wrap_content" | |
android:layout_width="wrap_content" | |
android:text="push" | |
/> | |
<android.support.v4.widget.NestedScrollView | |
android:id="@+id/childScrollView" | |
android:overScrollMode="always" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
> | |
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
> | |
<TextView | |
android:overScrollMode="always" | |
android:id="@+id/textView1" | |
android:layout_width="match_parent" | |
android:layout_height="500dp" | |
android:background="#333" | |
/> | |
<TextView | |
android:layout_below="@id/textView1" | |
android:id="@+id/textView2" | |
android:layout_width="match_parent" | |
android:layout_height="800dp" | |
android:background="#999"/> | |
</RelativeLayout> | |
</android.support.v4.widget.NestedScrollView> | |
</LinearLayout> | |
</android.support.v4.widget.NestedScrollView> | |
NestedScrollViewはRecyclerViewと相性が悪いらしくて.. | |
http://stackoverflow.com/questions/31000081/how-to-use-recyclerview-inside-nestedscrollview | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment