开发者

Android XML Layout Help: How to layout UI so an ad is always visible

开发者 https://www.devze.com 2023-03-18 18:26 出处:网络
I have playing around with my XML layout for what seems like weeks now, and i just cannot get it to work how i would like it to.

I have playing around with my XML layout for what seems like weeks now, and i just cannot get it to work how i would like it to.

I would like the admob ad to always been visible at the bottom of the screen, I have tried to do it like this, but because the gridview is graphically intensive i think the admob ad is being left behind somewhat.(It only shows 30% of the time, roughly)

Hopefully someone will be able to show me how to lay it out correctly. I.E Force the ad at the bottom of the screen!

Thanks Lucy

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi开发者_C百科d"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="wrap_content">


 <ImageView android:id="@+id/ImageView03" 
  android:src="@drawable/banner_gallery"
android:layout_height="60dp" 
android:layout_width="fill_parent"></ImageView>

    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridview" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:columnWidth="90dp"
        android:numColumns="auto_fit" android:verticalSpacing="7dp"
        android:horizontalSpacing="7dp" android:stretchMode="columnWidth"
        android:gravity="center" android:layout_gravity="bottom"
        android:layout_marginTop="10dp"></GridView>




    <RelativeLayout 
    android:layout_marginTop="-50dip" 
    android:gravity="bottom" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent">

   <com.admob.android.ads.AdView
    android:id="@+id/ad"
   android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

   </RelativeLayout>

   </LinearLayout>


Use Relative Layout as parent layout instead of linear layout and use android:layout_alignParentBottom="true" to the relative layout of addview


Try something like this. You only need one RelativeLayout and then layout the different views according to each other,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
 <ImageView android:id="@+id/ImageView03" 
      android:src="@drawable/banner_gallery"
      android:layout_height="60dp" 
      android:layout_alignParentTop="true"
      android:layout_width="fill_parent"/>
 <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridview" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:columnWidth="90dp"
        android:numColumns="auto_fit" android:verticalSpacing="7dp"
        android:horizontalSpacing="7dp" android:stretchMode="columnWidth"
        android:layout_below="@id/ImageView03"
        android:layout_above="@id/ad"
        android:layout_marginTop="10dp"/>
 <com.admob.android.ads.AdView
    android:layout_alignParentBottom="true"
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

0

精彩评论

暂无评论...
验证码 换一张
取 消