Reputation: 150
I am trying to build an application. I want to show a banner add in the layout such that the banner add is always shown on the screen but the text inside is scroll able.
This is my layout but for some reason the banner ad is not visible. If I shift the banner ad inside the linear layout then the banner ads is visible but I have to scroll it in order to see it. I want it permanently in the bottom at the screen.
I have already seen a couple of examples on stackoverflow and they didn't work. Any help is appreciated.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/photoandname"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:paddingLeft="6dp"
android:paddingTop="6dp"
android:foregroundGravity="center"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
app:srcCompat="@mipmap/ic_launcher"
android:id="@+id/displaypic"
android:layout_weight="1"
android:layout_gravity="center"
android:foregroundGravity="center" />
<TextView
android:text="Your Name Comes Here"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="11dp"
android:id="@+id/name"
android:textSize="24sp"
android:layout_weight="1"
android:layout_gravity="center"
android:foregroundGravity="center"
android:gravity="center" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adView"
android:id="@+id/scroll"
android:layout_below="@+id/photoandname"
android:layout_alignParentStart="true"
android:paddingLeft="6dp"
android:paddingBottom="10dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/photoandname"
android:layout_alignParentStart="true"
android:id="@+id/data"
android:paddingTop="6dp"
android:paddingLeft="6dp"
android:paddingBottom="50dp">
<TextView
android:text="Register Number : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/registernumber"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Section : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/section"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Semester : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/year"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Office Name : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/officename"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Course Name : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coursename"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Father's Name : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fathername"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Date of Birth : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/dob"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Sex : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sex"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Blood Group : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bloodgroup"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Address : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/address"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Email : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/email"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Student Contact Number : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pincode"
android:textSize="18sp"
android:paddingBottom="6dp" />
<TextView
android:text="Validity : "
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/validity"
android:textSize="18sp"
android:paddingBottom="6dp" />
</LinearLayout>
</ScrollView>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/Profile_Banner">
</com.google.android.gms.ads.AdView>
Upvotes: 0
Views: 629
Reputation: 23881
try using this format:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<AdView
android:id="@+id/yourAdview"
android:layout_alignParentBottom="true"
...
/>
<ScrollView
android:layout_alignParentTop="true"
android:layout_above="@id/yourAdview"
android:layout_below="@id/photoandname">
<LinearLayout
...>
//scrollview contents here
...
</LinearLayout>
</ScrollView>
</RelativeLayout>
Upvotes: 0
Reputation: 119
Please make scrollview and linear layout (which is inside scrollview)wrap_content instead of match_parent thats why banner ad not getting enough space to show.
Upvotes: 0
Reputation: 86
Let me know if it works for you
Assuming your activity name is ABCActivity and your package is com.username.appname and your xml file name is abc_activity
Make a new xml => new_activity
Change the content view in the activity
and setContentView(R.layout.new_activity);
new_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.username.appname.ABCActvity">
<include layout="@layout/abc_activity" />
<!-- your orignal activity name -->
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
ads:adSize="BANNER"
ads:adUnitId="@string/Profile_Banner">
</com.google.android.gms.ads.AdView>
</android.support.design.widget.CoordinatorLayout>
Upvotes: 1