以下設置不起作用,有人知道爲什麼(我似乎無法找到片段中自定義曲面視圖的示例)。如何顯示包含自定義SurfaceView的片段
我surfaceView類是目前只是空:
class MySurfaceView extends SurfaceView implements Runnable{
public MySurfaceView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void run() {
// TODO Auto-generated method stub
}
}
我對片段XML看起來是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout2"
android:layout_width="500dp"
android:layout_height="600dp"
android:layout_gravity="fill"
android:background="#000000" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<com.example.android.fragments.MySurfaceView
android:id="@+id/surfaceview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
然後在實際片段本身的OnCreateView我打電話:
return inflater.inflate(R.layout.article_view, container, false);
任何想法,爲什麼這不會在一起?
這事做與XML,因爲當我做
<SurfaceView
android:id="@+id/surfaceview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
然後正常工作。
我認爲你的答案是不正確的,因爲「要爲你的片段繪製一個UI,你必須從這個方法返回一個視圖,這是你的片段佈局的根。 SurfaceView不是根視圖,它只是XML文檔中的一個組件,因爲我也有一個按鈕。所以這就是我正在做的「返回inflater.inflate(R.layout.article_view,容器,false);」我膨脹並返回包含SurfaceView的根視圖。 – drlobo 2013-02-15 15:45:15