Android的布局与ListView和按钮 [英] Android Layout with ListView and Buttons

查看:160
本文介绍了Android的布局与ListView和按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这个特定的布局仅仅是讨厌我。而且似乎无法找到一种方法,有一个列表视图,有一排按键在底部,所以该列表视图不会延伸到按钮的上方,因此,按钮总是捕捉到屏幕的底部。这就是我想要的:

删除死ImageShack链接

现在看来似乎应该是很容易的,但一切我已经试过失败。任何帮助?

下面是我目前的code:

  RelativeLayout的集装箱=新RelativeLayout的(这一点);
    container.setLayoutParams(新RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));

    // **添加的LinearLayout与按钮(S)

    的LinearLayout按钮=新的LinearLayout(本);

    RelativeLayout.LayoutParams bottomNavParams =新RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    bottomNavParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    bottomNavParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    buttons.setLayoutParams(bottomNavParams);


    的ImageButton newLayer =新的ImageButton(本);
    newLayer.setImageResource(R.drawable.newlayer);
    newLayer.setLayoutParams(新LinearLayout.LayoutParams(45,LayoutParams.FILL_PARENT));
    buttons.addView(newLayer);

    container.addView(按钮);

    // **添加的ListView

    layerview =新的ListView(本);

    RelativeLayout.LayoutParams listParams =新RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
    listParams.addRule(RelativeLayout.ABOVE,buttons.getId());

    layerview.setLayoutParams(listParams);

    container.addView(layerview);
 

解决方案

我想这是你所期待的。

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT>

    <按钮机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / testbutton
        机器人:文本=@字符串/你好机器人:layout_alignParentBottom =真/>

    < ListView的机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT机器人:ID =@ + ID /列表
        机器人:layout_alignParentTop =真正的机器人:layout_above =@ ID / testbutton/>

< / RelativeLayout的>
 

Alright, this specific layout is just annoying me. And can't seem to find a way to have a listView, with a row of buttons at the bottom so that the listview doesn't extend over top of the buttons, and so the buttons are always snapped to the bottom of the screen. Here's what I want:

removed dead ImageShack link

It seems like it should be so easy, but everything I've tried has failed. Any help?

Here's my current code:

    RelativeLayout container = new RelativeLayout(this);
    container.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));

    //** Add LinearLayout with button(s)

    LinearLayout buttons = new LinearLayout(this);

    RelativeLayout.LayoutParams bottomNavParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    bottomNavParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    bottomNavParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    buttons.setLayoutParams(bottomNavParams);


    ImageButton newLayer = new ImageButton(this);
    newLayer.setImageResource(R.drawable.newlayer);
    newLayer.setLayoutParams(new LinearLayout.LayoutParams(45, LayoutParams.FILL_PARENT));
    buttons.addView(newLayer);

    container.addView(buttons);

    //** Add ListView

    layerview = new ListView(this);

    RelativeLayout.LayoutParams listParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    listParams.addRule(RelativeLayout.ABOVE, buttons.getId());

    layerview.setLayoutParams(listParams);

    container.addView(layerview);

解决方案

I think this is what you are looking for.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">

    <Button android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:id="@+id/testbutton"
        android:text="@string/hello" android:layout_alignParentBottom="true" />

    <ListView android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:id="@+id/list"
        android:layout_alignParentTop="true" android:layout_above="@id/testbutton" />

</RelativeLayout>

这篇关于Android的布局与ListView和按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆