问题
I want to put an ad layout at the bottom of a ListView. I want it to stick to the bottom of the page and the listview almost scrolling going behind it.
This is what I have and it doesn't work:
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:longClickable="true" >
</ListView>
<LinearLayout
android:id="@+id/adLayout"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_horizontal" >
</LinearLayout>
It is that bottom LinearLayout I need to just stay at bottom. And I want ListView to go all the way to the bottom. Can anyone advise?
回答1:
Change attributes of your ListView
to :
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:longClickable="true" >
</ListView>
EDIT: Also check that parent layout of your piece of code is LineareLayout
with attribute android:orientation="vertical"
回答2:
here is the solution of your problem
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/adView"
android:layout_alignParentTop="true" >
</ListView>
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
</RelativeLayout>
来源:https://stackoverflow.com/questions/13888574/sticky-footer-below-listview-in-android-layout