0

MyClass が基本的に View を拡張する次のコードがあります。setContentView(R.layout.activity_mainlcass_app)両方を使用setContentView(myDrawing)し、MyClass で描画した 2D グラフィックスを表示する必要があるかどうか疑問に思っていました。

public class MainClass extends Activity {
    MyClass myDrawing;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mainlcass_app);

        myDrawing = new myDrawing(this);
            setContentView(myDrawing);
            myDrawing.requestFocus();
    }
}
4

4 に答える 4

2

いいえ、できません。2 番目のレイアウトは、親ビューでオーバーライドされます。

于 2013-01-25T07:12:21.093 に答える
2

メインレイアウト(activity_mainlcass_app)に追加するだけですMyClass

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

    <com.example.MyClass
        android:id="@+id/myclass"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
于 2013-01-25T07:14:15.143 に答える
0

他の上に新しい描画が必要な場合 (レイアウト サイズが異なる可能性があります)、元のレイアウトに FrameLayout を使用し、重力を使用して新しい描画を配置し、アクティビティの addView メソッドを使用します。

于 2013-01-25T09:37:55.790 に答える
0

このようにしてみてください

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

<com.example.firstactivity
android:layout_width="fill_parent"
  android:layout_height="fill_parent"/>


<com.example.secondactivity
android:layout_width="fill_parent"
  android:layout_height="fill_parent"/>

</LinearLayout>

詳細については、このリンクとこの例を確認してください

于 2013-01-25T07:18:40.223 に答える