我試圖創建一個類似於Youtube播放器的Android視頻播放器。我將按照以下步驟創建播放器:安卓視頻播放器With small layout
- 頂層佈局設計。
- VideoPlayer(surfaceView)的中間佈局。
- 的進度底部佈局(提示:所有的佈局裝箱動態)
這是我的要求的模板。
我面臨的問題是SurfaceView
正在顯示的全長。它隱藏了頂部和底部佈局。
我能做些什麼來使頂部和底部佈局出現?
我試圖創建一個類似於Youtube播放器的Android視頻播放器。我將按照以下步驟創建播放器:安卓視頻播放器With small layout
這是我的要求的模板。
我面臨的問題是SurfaceView
正在顯示的全長。它隱藏了頂部和底部佈局。
我能做些什麼來使頂部和底部佈局出現?
這是我如何動態定位表面視圖。也許有更多用戶界面知識的人會做不同的事情......我希望看到。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create objects.
try {
mCamera = Camera.open();
}
catch (Exception e) {
Log.e("onCreate", "could not open camera", e);
}
mLiveGraphView = new LiveGraphView(this);
mCameraPreview = new CameraPreview(this, mCamera);
// Create RelativeLayout for layout root.
mLayoutRoot = new RelativeLayout(this);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
// Add GraphView to layout.
RelativeLayout.LayoutParams lpGraph = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
mLiveGraphView.setLayoutParams(lpGraph);
mLayoutRoot.addView(mLiveGraphView);
// Add SurfaceView to layout.
List<Camera.Size> ls = mCamera.getParameters().getSupportedPreviewSizes();
int n = ls.size();
int widthMin = 10000;
int imin = -1;
for (int i=0; i<n; i++) {
if (DEBUG)
Log.d(TAG, "supported preview width x height: " + ls.get(i).width + " x " + ls.get(i).height);
if (widthMin > ls.get(i).width) {
widthMin = ls.get(i).width;
mCameraPreviewSize = ls.get(i);
imin = i;
}
}
if (imin >= 0) {
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(mCameraPreviewSize.width, mCameraPreviewSize.height);
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
parameters.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_DAYLIGHT);
parameters.setSceneMode(Camera.Parameters.SCENE_MODE_SPORTS);
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
mCamera.setParameters(parameters);
RelativeLayout.LayoutParams lpSurface = new RelativeLayout.LayoutParams(
ls.get(imin).width, ls.get(imin).height);
lpSurface.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lpSurface.addRule(RelativeLayout.CENTER_HORIZONTAL);
mCameraPreview.setLayoutParams(lpSurface);
mLayoutRoot.addView(mCameraPreview);
}
// Provide Android framework with layout root.
setContentView(mLayoutRoot, rlp);
}
你用什麼作爲父級佈局?如果頂部和底部視圖中的任何一個都疊加在VideoView的頂部(這是YouTube所做的)?
這是一個使用RelativeLayout的示例佈局,顯示了這種方法:(注意:ViewGroups的位置很重要,它決定哪些視圖位於「頂部」與「下面」之間,靠近文件底部的ViewGroup更高「頂部「)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<LinearLayout
android:id="@+id/linearLayoutTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the top container!" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the bottom container!" />
</LinearLayout>
</RelativeLayout>
如果你不想在頂部和底部的觀點不重疊,你可以使用的LinearLayout(W /垂直方向和適當layout_heights):
<?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" >
<LinearLayout
android:id="@+id/linearLayoutTop"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the top container!" />
</LinearLayout>
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/linearLayoutBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the bottom container!" />
</LinearLayout>
</LinearLayout>
http://stackoverflow.com/questions/16403616/layout-aligning-issue-in-android-layout PLease喜歡這個鏈接..我更新了那裏的代碼.. – 2013-05-06 17:13:16
的http://計算器。 com/questions/16403616/layout-aligning-issue-in-android-layout請更新我的代碼D問題 - 我粘貼在那裏的代碼.. – 2013-05-06 17:09:52