android - ListView 和按钮(安卓)

标签 android xml listview android-styles

我想在 listView 中增加一个下降按钮: Drawing of what I want

我尝试实现这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#214075"
    android:layout_height="match_parent"
    android:orientation="vertical" >



    <ListView
        android:id="@+id/listbascet"
        android:layout_width="match_parent" 
        android:layout_height="0dip" 
            android:layout_weight="1" />

    <Button
        android:id="@+id/sendtoEmail"
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="0"
        android:text="Заказать услуги" />

</LinearLayout>

最佳答案

您最好从 XML 中删除该按钮并将其添加到另一个 XML 中。

然后您可以使用inflate 获取按钮并将其添加为页脚 View 到原始 ListView 。

这样它将位于列表的末尾并且也会滚动!

如何充气:

LayoutInflater inflater = (LayoutInflater) 
                     getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.mylayout, null);

Button item = (Button) view.findViewById(R.id.item); // how to reference your button

如何添加页脚:

listView.addFooterView(view); // view is the inflated layout.

this 中包含有关页脚 View 的更多详细信息也回答一下。

关于android - ListView 和按钮(安卓),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30013295/

相关文章:

java - OnClickListener的不同实现方式

android - adb pull 动态创建的文件路径

java - 嵌套的 Do-While 循环通过游标进行索引 - 不起作用

java - 如何在 List<Serializable> 内容 JaxB 中添加元素?

java - 解码具有相同名称属性的@XMLElement

c# - 锁定文件以防止多个用户访问它的最佳方法是什么

mysql - 文本框输入作为 ListView 中的列标题和 vb6 和 mysql 中的表列

Android:通过 AOSP 源代码创建新的系统权限。

android - 在 android 中用于单独 ListView 的最佳 native 组件

listview - 如何使ListView中的文本居中?