0

所以我有以下 onCreate 函数

        @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       mylocation = new MyLocation(this);

       double distance = distance (mylocation.lat, mylocation.lng, messagelat, messagelong);
       Log.d("Distance",Double.toString(distance));
       mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
       mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
       mView = new SampleView(this,Double.toString(distance));
       **this.setContentView(R.layout.activity_clouds);**
       this.button = (Button)this.findViewById(R.id.close);
       this.button.setOnClickListener(new OnClickListener() {
         public void onClick(View v) {
             Intent myIntent = new Intent(Activity1.this, CameraPreview.class);
             Activity1.this.startActivity(myIntent);
         }
       });

       **setContentView(mView);**

   }

我的问题是我想同时使用来自 activity_cloud.xml 和 SampleView 的视图,但是如果我这样做,我只会得到示例视图!我想在 SampleView 类中添加一个按钮和覆盖层......非常感谢

4

1 回答 1

0

您可以在常规 xml 布局中使用自定义视图。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical">
<com.something.something.SampleView
        android:id="@+id/sample_view"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" />
<Button android:layout_height="0dp"
                                   android:layout_width="fill_parent"
                                   android:layout_weight="1"
                                   android:id="@+id/close"/>

于 2012-08-08T03:46:11.930 回答