【发布时间】:2015-06-30 01:26:04
【问题描述】:
我有一个可以播放直播视频的表面视图。我需要它在变成横向时全屏显示。我有一个带有片段的活动,其中包含表面视图和显示其他实时流的网格视图。这是片段的布局 -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
>
<RelativeLayout
android:id="@+id/guiLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical"
android:layout_weight="0.6">
<FrameLayout
android:id="@+id/videoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="0dp">
<SurfaceView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:visibility="visible">
</SurfaceView>
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layoutGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="@android:color/white">
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:horizontalSpacing="2dp"
android:isScrollContainer="false"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp"
android:background="@color/transparent"
android:layout_gravity="center_horizontal|bottom" />
</RelativeLayout>
所以我在activity中的onConfigChanged调用了super onConfigChanged,然后调用了fragments的onRotate方法,传递给它newConfig——
public void onRotate(Configuration newConfig)
{
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
Log.e(TAG, "CHANGING");
getView().findViewById(R.id.guiLayout).setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
if(gridView != null)
gridView.setVisibility(View.GONE);
getView().findViewById(R.id.layoutGrid).setVisibility(View.GONE);
}
else
{
Log.e(TAG, "CHANGING PORTRAIT");
getView().findViewById(R.id.guiLayout).setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT ,0.6f));
if(gridView != null)
gridView.setVisibility(View.VISIBLE);
else
gridView = (GridView) getView().findViewById(R.id.gridView);
}
这个想法是,如果我将我的 guiLayout 调整为全屏,它的子元素应该更改为适合,因为它们被设置为 MATCH_PARENT。但事实并非如此,guilayout 调整为全屏,但子项仍占原始重量的 40%。我尝试了很多不同的方法来让孩子们匹配他们的父母,但都没有奏效。任何关于我做错了什么的建议将不胜感激。
【问题讨论】:
标签: android android-layout android-fragments surfaceview