我有一个显示列表视图的xml布局。我还想在此列表视图的下面显示一个admob横幅,并且无论用户滚动列表视图如何,我都希望始终在底部显示它。我有这个xml布局:
<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:layout_width="fill_parent"
android:id="@+id/home_layout"
android:orientation="vertical"
android:layout_height="wrap_content">
<!-- Put all your application views here, such as buttons, textviews, edittexts and so on -->
<ListView
android:id="@+id/lvImages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dividerHeight="1dp" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:orientation="horizontal"
android:id="@+id/footerLayout"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_alignBottom="@+id/home_layout">
</LinearLayout>
而且我在onCreate方法中创建了Admob标语:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listado_imagenes_subidas_main);
// Crear adView.
adView = new AdView(this);
adView.setAdUnitId("XXXXXXXXXXXXXXXXXXX");
adView.setAdSize(AdSize.BANNER);
LinearLayout layout = (LinearLayout)findViewById(R.id.footerLayout);
layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
// load list application
listImagenes = (ListView)findViewById(R.id.lvImages);
// create new adapter
ImagenesAdapter adapter = new ImagenesAdapter(this, ListadoImagenes());
// set adapter to list view
listImagenes.setAdapter(adapter);
}
如何在列表视图下面显示粘性页脚区域?
谢谢你。
您需要稍微修改一下布局。
尝试一下,调整两个子线性布局中的android:layout_weight=""
以获得您喜欢的高度。
这样做吧。
尝试一下:-
*
<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:layout_width="fill_parent"
android:id="@+id/home_layout"
android:orientation="vertical"
android:layout_height="wrap_content">
<!-- Put all your application views here, such as buttons, textviews, edittexts and so on -->
<ListView
android:id="@+id/lvImages"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:dividerHeight="1dp" />
<LinearLayout android:layout_width="match_parent"
android:orientation="horizontal"
android:id="@+id/footerLayout"
android:layout_height="wrap_content"
android:gravity="bottom"
>
</LinearLayout>
</LinearLayout>
添加此android:layout_centerHorizontal =“ true”android:layout_alignParentBottom =“ true”