2013-02-04 39 views
0

我該如何創建2個分界面在Android上的屏幕的一半?例如它們中的每一個佔據屏幕的1/2。我怎樣才能創建2分面在Android上的屏幕的一半?

我得到這個異常: 當我這樣做我的應用程序的工作原理:當我切換到這一點,

<?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" 
> 
    <com.example.android.apis.graphics.Preview android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" android:id="@+id/view1" /> 

</LinearLayout> 

即使沒有使用「@ + ID /視圖2」,像這樣:

<?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" 
> 
    <com.example.android.apis.graphics.Preview android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" android:id="@+id/view1" /> 


    <com.example.android.apis.graphics.Preview android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" android:id="@+id/view2" /> 

</LinearLayout> 

我從這個得到一個空指針異常:

Choreographer.doCallbacks(int, long) line: 558 
Choreographer.doFrame(long, int) line: 525 
Choreographer$FrameDisplayEventReceiver.run() line: 711 
Handler.handleCallback(Message) line: 615 
Choreographer$FrameHandler(Handler).dispatchMessage(Message) line: 92 
Looper.loop() line: 137 
ActivityThread.main(String[]) line: 4921  
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
Method.invoke(Object, Object...) line: 511 
ZygoteInit$MethodAndArgsCaller.run() line: 1038 
ZygoteInit.main(String[]) line: 805 
NativeStart.main(String[]) line: not available [native method] 

回答

0
<LinearLayout android:layoutHeight="fill_parent" 
       android:layoutWidth="fill_parent" 
       android:orientation="horizontal" > 
    <SurfaceView1 android:layoutWidth="fill_parent" 
        android:layoutHeight="fill_parent" 
        android:layoutWeight="1" /> 
    <SurfaceView2 android:layoutWidth="fill_parent" 
        android:layoutHeight="fill_parent" 
        android:layoutWeight="1" /> 
</LinearLayout> 

重要的部分使它們在重量和fill_parent上都相等。要解決Android中的奇怪錯誤,您可能需要指定佈局的寬度爲0dip。

相關問題