【问题标题】:CustomizedView in android - listView and Button UIandroid 中的 CustomizedView - listView 和 Button UI
【发布时间】:2012-06-20 10:24:30
【问题描述】:

我正在尝试在 android 中开发给定的 UI,有一个 ListView,在它上面有一个可见的按钮,listView 的高度是 Fill_PARENT,按钮固定在它的位置。

如何在视图上方添加视图?或有关使用 XML 或自定义视图创建此布局的任何想法。

【问题讨论】:

    标签: android listview android-layout android-custom-view


    【解决方案1】:

    您需要为您的项目创建布局,并覆盖BaseAdapter 为您的自定义ListView 创建您自己的适配器,

    查看此tutorial 了解如何创建自定义ListView

    看到这个问题与你的情况类似:how to customize listview row android

    最后,这个tutorial 非常好,它可以管理列表项的选择状态:

    【讨论】:

    • 我的问题与ListView适配器无关,我必须在listView上方显示Button。这就像在iOS中另一个视图的子视图中添加一个视图。
    • 您想在您的 listView 上方有一个按钮 ???所以将它添加到你的 xml 布局中,我不明白你真正想要什么:)
    • 是的,按钮应该在 listView 上方。如何使用 xml 布局或 runtimeView。
    • 我不知道您是否希望您的按钮在您的 listView 上方始终可见,因此您无需在运行时添加它,只需将其添加到布局 xml 中,通过使用 RelativeLayout ,并将您的 ListView 放在按钮下方:)
    【解决方案2】:

    我认为根据我对您问题的理解,您似乎正在寻找FrameLayout。所以有一个列表视图,顶部是一个按钮。正确的?试试这个。

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout android:id="@+id/mainlayout" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
    
    <ListView android:layout_height="fill_parent" android:layout_width="fill_parent" android:padding="10dp" android:id="@+id/myListView"/>
    
    <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/buttondrawable" />
    </FrameLayout>
    

    【讨论】:

    • 感谢我使用 FrameLayout 作为父级的线索,它似乎可以正常工作。
    • 顺便问一下,你是不是在做类似(Path App)的按钮? - 只是出于我的好奇!
    • @Wesley : 你有什么想法或代码可以像路径应用程序底部的按钮添加一样吗??
    • @Wesley:如果你想要更完美的路径应用按钮的解决方案;看到这个线程;)stackoverflow.com/questions/9922127/…,享受;)
    • 谢谢,我也看到了 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    相关资源
    最近更新 更多