相关疑难解决方法(0)

使用缓冲视频更改Android VideoView方向

我正在尝试复制Android市场中最新YouTube应用的功能.观看视频时,有两个独立的布局,一个是纵向提供额外的信息,一个是横向,提供视频的全屏视图.

YouTube应用程序纵向布局
YouTupe应用程序处于纵向模式

YouTube应用横向布局
横向模式的YouTube应用

(抱歉照片的随机性,但它们是我能找到的第一个实际布局照片)

这通常很容易做到 - 只需在layout-land中指定一个替代布局,一切都会很好.YouTube应用程序的功能非常好(以及我想要复制的内容)是在方向更改时,视频会继续播放,而不必从头开始重新缓冲.

我已经发现,覆盖onConfigurationChange()并设置新的LayoutParameters将允许我在不强制拒绝的情况下调整视频大小 - 但是当多次旋转屏幕时,视频会随机缩放到不同的宽度/高度.我已尝试在VideoView上进行各种invalidate()调用,尝试在父RelativeLayout容器上调用RequestLayout()并尝试尽可能多的不同内容,但我似乎无法让它正常工作.任何建议将不胜感激!

这是我的代码:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        questionText.setVisibility(View.GONE);
        respond.setVisibility(View.GONE);
        questionVideo.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    } else {
        questionText.setVisibility(View.VISIBLE);
        respond.setVisibility(View.VISIBLE);
        Resources r = getResources();
        int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150.0f, r.getDisplayMetrics());
        questionVideo.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, height));
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:我在logcat中发现了一些有趣的输出,当我的视频旋转时出现这似乎是罪魁祸首 - 虽然我不知道如何解决它:

正确调整大小时的Logcat输出(占用整个窗口)

注意h = 726

12-13 15:37:35.468  1262  1270 I ActivityManager: Config changed: { scale=1.0 imsi=310/4 loc=en_US touch=3 keys=1/1/2 nav=1/1 orien=2 layout=34 uiMode=17 seq=210}
12-13 15:37:35.561  1262  1268 I …
Run Code Online (Sandbox Code Playgroud)

android android-orientation android-videoview

50
推荐指数
5
解决办法
6万
查看次数

ScrollView中的Android :: VideoView

我有一个在scrollView中的VideoView.当我滚动scrollView时,VideoView不会滚动它.这就像它的位置是固定的.如何通过滚动scrollView中的所有其他元素正确滚动VideoView?

video android scroll scrollview android-videoview

13
推荐指数
2
解决办法
9283
查看次数

有视频浏览功能的Android Scrollview会出现问题

我有一个在scrollView中的VideoView.当我滚动scrollView时,VideoView不会滚动它.这就像它的位置是固定的.这是我的布局:

<?xml version="1.0" encoding="utf-8" ?> 
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF">
  <LinearLayout android:id="@+id/BackBar" android:orientation="vertical" android:layout_width="fill_parent" android:paddingTop="2dp" android:layout_height="wrap_content" android:background="#D6DEAA">
  <Button android:id="@+id/BackButton" android:layout_gravity="left" android:text="@string/BackButtonText" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 
  </LinearLayout>
  <ScrollView android:id="@+id/scroll1" android:layout_height="fill_parent" android:layout_width="fill_parent">
  <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF">
  <LinearLayout android:id="@+id/contentVideo" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="30px" android:paddingTop="15px" android:background="#FFFFFF">
  <TextView android:id="@+id/learn_hiv_blck1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/learn_hiv_blck1" android:textColor="#000000" android:textStyle="italic" android:background="#FFFFFF" android:layout_gravity="left" /> 
  <TextView android:id="@+id/learn_hiv_blck2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="15px" android:text="@string/learn_hiv_blck2" android:textColor="#000000" android:background="#FFFFFF" android:layout_gravity="left" /> 
  <TextView android:id="@+id/learn_hiv_blck3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="15px" android:text="@string/learn_hiv_blck3" android:textColor="#000000" android:background="#FFFFFF" android:layout_gravity="left" /> 
  <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#FFFFFF">
  <VideoView android:id="@+id/VideoView" …
Run Code Online (Sandbox Code Playgroud)

video layout android scrollview android-videoview

7
推荐指数
1
解决办法
1万
查看次数