2

Android 2.2 アプリケーションを SurfaceView をベース ビューとして起動し、その上にボタンを画面の下部近くに配置しようとしています。これまでのところ、運がありません。起動しようとするたびにクラッシュします。アクティビティがマニフェストに登録されていることを確認しました。

ここに私のJavaコードがあります:

public class Dragable extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

そしてここに私のmain.xml

<?xml version="1.0" encoding="utf-8"?>
<SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/surface_home"
    >
    <Button
        android:id="@+id/add_new"
        android:text="@string/add_new"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
    />
</SurfaceView>

そして私のマニフェスト:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Dragable"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="8" />

</manifest> 

ここに私のエラーがあります:

11-29 11:58:52.620: ERROR/AndroidRuntime(512): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.Dragable}: java.lang.ClassCastException: android.view.SurfaceView

SOで検索を行うことに関連するものを見つけることができないようです。これが以前に尋ねられた場合、私の謝罪。

4

2 に答える 2

4

今、私は問題を見ます。SurfaceViewはコンテナではありません。つまり、 extendsではないため、 a を a の中にViewGroup入れることはできません。できることは、と をでラップすることです。ButtonSurfaceViewSurfaceViewButtonRelativeLayout

于 2010-11-29T17:32:09.443 に答える
-1

コンポーネントを配置するためにコンテナを使用していません。これを使用して変更を加えます

 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/surface_home"
>
<Button
    android:id="@+id/add_new"
    android:text="@string/add_new"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
/>
 </SurfaceView>
</FrameLayout>
于 2010-11-29T17:38:56.247 に答える