【问题标题】:How to manipulate the ListView and layout in the android xml如何在 android xml 中操作 ListView 和布局
【发布时间】:2012-08-03 19:41:22
【问题描述】:

我试图操纵它来做以下事情,但到目前为止它只会导致沮丧......以下是我想要完成的事情的糟糕描绘:

http://i.stack.imgur.com/WZOta.png

http://i.stack.imgur.com/6cEQk.png

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >


<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >


    <ListView


        android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="419dp" >


    </ListView>

        <TextView 
            android:id="@+id/android:empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/FAP001"            
         />
        <Button
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="+1" />

</LinearLayout>
</ScrollView>

我不确定列表视图是否是要走的路。我什至不确定线性布局是否是一个好的选择。我试图让最终结果接近第二张图像上的内容。 提前致谢!!!

【问题讨论】:

  • ListView 本身就是一个滚动视图,因此不应包含在 ScrollView 中。从您的草图来看,ListView 绝对是正确的方法。
  • 如果你想要的是一个在每个项目中都有几个“可配置”字段的列表视图,也许你应该考虑使用 listadapter 和 arrayadapter。检查此链接。 vogella.com/articles/AndroidListView/article.html希望就是你所需要的。

标签: android xml listview layout android-linearlayout


【解决方案1】:

您不能在 ScrollView 中放置 ListView。那是不可能的。因为那时 ListView 有两个选项可以滚动浏览内容,正如您所愿。这是行不通的。

更多信息:

https://groups.google.com/forum/m/?fromgroups#!topic/android-beginners/LRpLgGOy2Pc

如果您想拥有一个包含 3 个“部分”的 ListView,我建议您使用自定义适配器创建自己的自定义 ListView。

这是一个自定义 ListView 的示例 http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

您可以只使用这个 ListView,只需根据自己的需要修改 Adapter 和 Row XML。

【讨论】:

    猜你喜欢
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-27
    • 2016-03-19
    • 2018-02-02
    • 2012-01-13
    • 1970-01-01
    相关资源
    最近更新 更多