我正在点击一个按钮将我的应用程序更改为横向,但问题是我在纵向模式下有一个列表视图和固定高度的视频视图,在更改为横向模式后我只想显示视频视图但是videoview显示的高度,但我想将其显示为全屏。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/relative2">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="visible"
android:id="@+id/video"
/>
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible" />
<ImageView
android:id="@+id/full"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:src="@drawable/ic_fullscreen"
android:visibility="visible"/>
<ImageView
android:id="@+id/potrait"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:src="@drawable/ic_normal_screen"
android:visibility="invisible"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/relative2">
<ListView
android:id="@+id/play_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/material_blue_grey_800"
android:dividerHeight="1dp"
android:footerDividersEnabled="false"
android:visibility="visible"/>
</RelativeLayout>
和更改方向的代码:
full.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
defaultScreenOrientationMode = getResources().getConfiguration().orientation;
defaultVideoViewParams = (RelativeLayout.LayoutParams) videoview.getLayoutParams();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
full.setVisibility(view.GONE);
potrait.setVisibility(view.VISIBLE);
play_list.setVisibility(View.GONE);
videoview.postDelayed(new Runnable() {
@Override
public void run() {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
// mc.show(0);
}
}, 700);
}
});
potrait.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int defaultScreenOrientationMode;
potrait.setVisibility(view.INVISIBLE);
full.setVisibility(view.VISIBLE);
play_list.setVisibility(view.VISIBLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
videoview.postDelayed(new Runnable() {
@Override
public void run() {
videoview.setLayoutParams(defaultVideoViewParams);
videoview.layout(10, 10, 10, 10);
// mc.show(0);
}
}, 700);
}
});
答案 0 :(得分:0)
要停止在方向更改时重新加载活动,请在清单
中写下以下代码<activity
android:name=".YourActivityName"
android:configChanges="orientation|screenSize">
</activity>
答案 1 :(得分:0)
LinearLayout layout = /* ... */;
layout.setOrientation(LinearLayout.VERTICAL);