2012-08-29 37 views
0

我在運行時根據數據庫中的記錄數量創建childviewview, 充氣視圖並添加到viewflipper。點擊每個viewflipper的childview時,應該有一些childs的newviewflipper。如何實現這一目標?Android:如何將一個viewflipper作爲孩子嵌入另一個Viewflipper

ViewFlipper.xml

<?xml version="1.0" encoding="utf-8"?> 
<ViewFlipper 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/flipper" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 

CustomViewSample.xml

<?xml version="1.0" encoding="utf-8"?>   
<com.sample.MjpegView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/fullscreen_video" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 

Java代碼的

ViewFlipper viewflipper = (ViewFlipper)findViewById(R.id.flipper); 

- **livevideocount** is an integer contains no of records from table. 

for(int i=0;i<livevideocount;i++) 
{ 
    MjpegView mv = (MjpegView)inflater.inflate(R.layout.CustomViewSample,null); 
    mv.setVisibility(MjpegView.VISIBLE); 
    viewflipper.addView(mv); 
} 

氯舔這個MjpegView對象應該生成另外一個包含3個子視圖的viewflipper。

任何人都可以幫助我嗎?

回答

0

您不應將動態內容直接充入ViewFliper。

您應該添加dyna_layout作爲<LinearLayout /><RelativeLayout />到您的ViewFlipper.xml,考慮dyna_layout作爲一個ViewGroup:

ViewGroup parent = (ViewGroup)(viewflipper.findViewById(R.id.dyna_view)); 

MjpegView mv = (MjpegView)inflater.inflate(R.layout.CustomViewSample, parent); 
mv.setVisibility(MjpegView.VISIBLE); //may use or not 
parent.addView(mv);