我有一个奇怪的问题findViewById
,如果我在布局中使用包含,任何东西都会返回 null。
这是我onCreate()
的,活动延长MapActivity
@Override
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
setContentView(R.layout.main);
// this will be null
MapView myMapViewmyMapView = (MapView) findViewById(R.id.mapview);
}
这是我的布局,main.xml
<!-- Loads of other layout elements up here, buttons, headers etc-->
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/demo_mode_layout"
android:orientation="vertical"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="@drawable/panel"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<!-- Include the mapview from an external mapview layout file-->
<include android:id="@+id/header" layout="@layout/maps"/>
</LinearLayout>
我引用的地图视图:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="my legit key here"
/>
如果在我的活动中,我使用R.layout.main
它设置内容视图将失败,但如果我将它设置为只是地图实体,R.layout.maps
那么一切都很好。
我想使用R.layout.main
这样我就可以为视图设置页眉、页脚、按钮菜单等,为什么这不起作用?