【问题标题】:ListView and Button(android)ListView 和 Button(android)
【发布时间】:2015-05-03 11:28:29
【问题描述】:

我想用一个增加下降按钮来制作 listView:

我尝试实现这一点:

<?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 得到什么结果?在这种情况下,我建议使用 RelativeLayout。使用 android:layout_below="@+id/your_list_view_id" 确保 Button 位于 Listview 下方。并且你将 ListView 的 layout_height 设置为 0dip,这意味着你不想显示它?我想你想把它设置为 wrap_content
  • 内嵌图片,删除了问候语。
  • @xwhyLikeThis 它的结果是我的 xml s22.postimg.org/ygpo9g169/image.png
  • @SebastianWalla 是的,我想将元素添加到 listView,然后按钮向下

标签: android xml listview android-styles


【解决方案1】:

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

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

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

如何充气:

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 答案中包含有关页脚视图的更多详细信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多