为什么添加View会动态地扭曲我的布局?

时间:2012-08-11 21:54:51

标签: android layout

我在RelativeLayout中包含了一个LinearLayout。我正在动态添加一个视图(横幅广告),但这会扭曲我的布局:横幅将显示在屏幕中间,大部分内容视图都会消失???

注意:动态添加视图是CustomEvent类的一部分。这是不受支持的网络的Admob中介所必需的。当Admob SDK添加支持网络的横幅时,布局不会倾斜。

可在此处找到屏幕截图:https://groups.google.com/forum/?hl=de&fromgroups#!topic/android-developers/I1w--u6fbvs%5B1-25%5D

这是有问题的代码:

    LinearLayout adContainer = (LinearLayout) activity.findViewById(R.id.ad_container);
    LinearLayout.LayoutParams params  = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 
            LinearLayout.LayoutParams.WRAP_CONTENT);
    adView.setLayoutParams(params);
    adContainer.addView(adView);

这是布局xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/layout_bg"
android:id="@+id/root_layout" >

  <LinearLayout 
      android:id="@+id/ad_container"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"></LinearLayout>

    <LinearLayout
    android:layout_below="@id/ad_container"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ImageButton
        android:id="@+id/button_previous_day"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/previous_saint_of_day" />

    <ImageButton
        android:id="@+id/button_previous_saint"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/previous_saint" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/text_view_date"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/date"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/text_view_saint_count"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/saint_name"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </LinearLayout>

    <ImageButton
        android:id="@+id/button_next_saint"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/next_saint" />

    <ImageButton
        android:id="@+id/button_next_day"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/next_saint_of_day" />
</LinearLayout>

<TextView
    android:id="@+id/text_view_name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="Medium Text"
    android:layout_below="@id/linearLayout1"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<WebView
    android:id="@+id/web_engine"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/text_view_name" /> 

<com.socialize.ui.actionbar.ActionBarView
    android:id="@id/socializeActionBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" />

</RelativeLayout>

有什么建议吗?

0 个答案:

没有答案