我有一个片段布局xml,RelativeLayout
包含AdView
,其属性为android:layout_alignParentBottom="true"
,但未在底部对齐。
我还有另一个布局xml,这段代码正在运行。请参阅下面的两个文件。
fragment_info :(此处AdView
未与底部对齐)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refreshIndicator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/blogInfoWebView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adViewBlogInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/blog_info_ad_unit" />
</RelativeLayout>
fragment_search :(此处AdView
与底部对齐)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Some code -->
</LinearLayout>
<include layout="@layout/fragment_post_list_web_view" />
</LinearLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adViewSearchList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/search_list_ad_unit" />
</RelativeLayout>
答案 0 :(得分:0)
使用线性布局检查此输出
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refreshIndicator"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<WebView
android:id="@+id/blogInfoWebView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adViewBlogInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/blog_info_ad_unit" />
</LinearLayout>