2017-01-16 56 views
0

我想切換從普通屏幕playerview到全屏視圖,並在這裏反之亦然 是我的代碼如何切換正常和完整的屏幕,反之亦然android中

mainactivity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/video_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/black" 
    android:orientation="vertical" > 

    <com.test.player.PlayerView 
     android:id="@+id/playerview" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="0dp"> 
    </com.test.player.PlayerView> 

    <com.test.player.DetailsInfo 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

PlayerView.java

public class PlayerView extends LinearLayout{ 
//Here i am adding surfaceview and 
// player control view 
} 

在播放器控制,我有一個選項,切換全屏到正常屏幕,反之亦然。

有人能幫我做到這一點。

+0

[Fullscreen Activity in Android?](http://stackoverflow.com/questions/2868047/fullscreen-activity-in-android) –

回答

1

你可以這樣做。

private boolean toggle = true; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_player); 


} 

public void onFullscreenButtonClick(View view) { 
    WindowManager.LayoutParams attrs = getWindow().getAttributes(); 
    if (toggle) { 
     attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; 
     toggle = false; 
    } else { 
     attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; 
     toggle = true; 
    } 
    getWindow().setAttributes(attrs); 
} 

讓我們知道它是否有效。

+0

我想讓playview獨自在全屏和普通屏幕之間切換,我的playerview從線性佈局擴展 – Jeggu