Android布局,如何在调用addView之前指定元素的顺序
我正在使用AdWhirl在我的免费应用程序中放置广告。我希望广告出现在地图视图下方和列表视图上方。不管我怎么做,我都不能让广告出现在任何地方,除了底部。目前,listView是在XML中膨胀的,但是AdWhirlView必须在Java代码中创建。因为我调用addView(adWhirlView)是在方向垂直的线性布局上,所以广告总是出现在底部。我如何定义广告应该放在哪里 以下是我的XML:Android布局,如何在调用addView之前指定元素的顺序,android,android-layout,android-linearlayout,Android,Android Layout,Android Linearlayout,我正在使用AdWhirl在我的免费应用程序中放置广告。我希望广告出现在地图视图下方和列表视图上方。不管我怎么做,我都不能让广告出现在任何地方,除了底部。目前,listView是在XML中膨胀的,但是AdWhirlView必须在Java代码中创建。因为我调用addView(adWhirlView)是在方向垂直的线性布局上,所以广告总是出现在底部。我如何定义广告应该放在哪里 以下是我的XML: <LinearLayout xmlns:android="http://schemas.androi
<LinearLayout 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/layout_main"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1">
<com.google.android.maps.MapView
....
</RelativeLayout>
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"/>
</LinearLayout>
试试下面的代码
<LinearLayout 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/layout_main"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1">
<com.google.android.maps.MapView
....
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:id="@+id/layout_ad"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"/>
</LinearLayout>
这样,您的列表视图将始终位于AdWhirl之后,如果没有要显示的广告,则列表视图将位于map之后perfect!最后,我错过了android:layout\u height=“wrap\u content”
AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR });
LinearLayout layout = (LinearLayout) findViewById(R.id.layout_ad);
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "Key");
Display d = this.getWindowManager().getDefaultDisplay();
RelativeLayout.LayoutParams adWhirlLayoutParams = new RelativeLayout.LayoutParams(d.getWidth(), 52);
layout.addView(adWhirlLayout, adWhirlLayoutParams);
layout.invalidate();