我想使用RecyclerView
并使用recyclerView.smoothScrollToPosition()
滚动页面播放视频。
当RecyclerView
VideoView
使用ViewHolder
onBindViewHolder(ViewHolder, position)
时,RecyclerView
位置无法匹配interface Control {
int getCurrentPosition() ;
}
Control control;
public RecyclerView.ViewHolder onCreateViewHolder() {
Log.i(TAG, "onCreateViewHolder()...page: " + control.getCurrentPosition() );
}
public void onBindViewHolder(ViewHolder, position){
Log.i(TAG, "onBindViewHolder()...position: " + position + ", page: " + control.getCurrentPosition() );
int page = control.getCurrentPosition();
// position maybe difference page value
}
当前位置,因此我无法控制VideoView。
适配器:
int page;
void onCreate() {
adapter = new Adapter(new Adapter.Control() {
@Override
public int getCurrentPosition() {
return page;
}
});
}
void scroll() {
Log.i(TAG, "page: " + page );
recyclerView.smoothScrollToPosition(page);
}
的活动:
page: 0
onCreateViewHolder()...page: 0
onBindViewHolder()...position: 0, page: 0
page: 1
onCreateViewHolder()...page: 1
onBindViewHolder()...position: 1, page: 1
onCreateViewHolder()...page: 1
onBindViewHolder()...position: 2, page: 1
page: 2
onCreateViewHolder()...page: 2
onBindViewHolder()...position: 3, page: 2
page: 3
page: 4
onBindViewHolder()...position: 4, page: 4
onBindViewHolder()...position: 5, page: 4
page: 5
page: 6
onBindViewHolder()...position: 6, page: 6
onBindViewHolder()...position: 7, page: 6
page: 7
page: 8
onBindViewHolder()...position: 8, page: 8
onBindViewHolder()...position: 9, page: 8
page: 9
日志:
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:src="@drawable/ic_favorite_border_white_24dp"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"/>