Reputation: 409
Hi I want to draw my ScrollView
on whole screen and ScrollView
content should be display on the whole screen
But I also want to show my ad on bottom of the screen. I have confusion here I just want to give ScrollView
a
Height something like (Fill parent - 20 px) and my ads should be display at (20 PX) at the bottom of the screen
Note that whatever in the scroll view it should be display on whole screen except (20 px ) of the bottom.
Upvotes: 0
Views: 1141
Reputation: 24848
// try this
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ScrollView>
<com.google.ads.AdView
android:id="@+id/adView1"
android:layout_width="match_parent"
android:layout_height="20dp"
app:adSize="SMART_BANNER"
app:adUnitId="ca-app-pub-9766031373541061/3761995838"
app:loadAdOnCreate="true"
app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
</com.google.ads.AdView>
</LinearLayout>
Upvotes: 0
Reputation: 6754
All 3 current answers use a RelativeLayout as the root element of the layout, this is bad for performance.
Use a FrameLayout instead, then to make your ScrollView fill_parent - 20px, set its height to fill_parent and its layout_marginBottom to 20px. Set the Ad View to layout_gravity="bottom" and its height to 20px.
In addition, you should make this 20px 20dp, move it into a values/dimens.xml file, and use this same value for the two parameter mentioned above. It's then easy to define different sizes per screen size/density.
Upvotes: 0
Reputation: 1420
use this layout:
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/your_ad_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="sample button" />
</LinearLayout>
<ScrollView
android:id="@+id/myscroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/your_ad_layout"
>
</>
</RelativeLayout>
Upvotes: 0
Reputation: 28823
You can try this:
<?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"
android:orientation="vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="20dip"
android:id="@+id/adView"
android:layout_alignParentBottom="true"
>
</LinearLayout>
<ScrollView
android:layout_alignTop="@id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Page content -->
</ScrollView>
</RelativeLayout>
So adView
will take fixed 20 dip portion and remaining part will be taken by ScrollView
.
Hope this helps.
Upvotes: 2