Привязать mediacontroller к определенному представлению
У меня есть следующие взгляды в деятельности:
<ScrollView
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20sp"/>
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="40dp" />
</LinearLayout>
</ScrollView>
В этом упражнении много текста, поэтому можно прокрутить. Я пытался установить view
в качестве якоря для медиа-контроллера, но медиа-контроллер всегда расположен внизу экрана (даже во время прокрутки).
View view = findViewById(R.id.view);
controller.setAnchorView(view);
Мой вопрос заключается в том, как привязать медиа-контроллер к view
так что он может прокручивать с view
,
1 ответ
Вместо использования просмотра вы можете использовать videoview. Вы можете добавить медиа-контроллер в videoview. Также это будет прокрутка с scrollview.
Используйте код ниже, это работает.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusableInTouchMode="true"
android:focusable="true"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/xyzString"
android:textSize="20sp" />
<VideoView
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="250dp"
android:focusable="true"/>
</LinearLayout>
</ScrollView>