【问题标题】:Fragment- create list view with image ,texts and 3 dots片段 - 创建带有图像、文本和 3 个点的列表视图
【发布时间】:2018-05-10 13:09:49
【问题描述】:

当用户点击 FULL-TIME 按钮时,我想打开应该显示包含 imagetexts 的列表视图的片段,和 3 个点 在每个视图的右端找到下面的图像。怎么做?
.

这是我的代码。 home.xml

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

    <RelativeLayout
        android:id="@+id/layout_2nd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/btn_full_time"
            android:layout_width="191dp"
            android:layout_height="60dp"
            android:layout_alignParentTop="true"
            android:text="@string/full_time" />

        <Button
            android:id="@+id/btn_part_time"
            android:layout_width="206dp"
            android:layout_height="60dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_toRightOf="@+id/btn_full_time"
            android:text="@string/part_time" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/layout_2nd">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ListView
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </ListView>
        </FrameLayout>

    </RelativeLayout>


</RelativeLayout>

我是否需要为每个视图创建单独的 xml,或者我可以通过编程方式进行吗?请推荐?

【问题讨论】:

  • 您需要以编程方式使用数据填充 ListView,有很多方法可以做到这一点。也许从这样的事情开始stackoverflow.com/questions/5070830/…
  • 您需要创建一个描述单个列表视图项的 xml。然后您需要创建一个适配器类/或者您可以使用您创建的 xml 文件使用 ArrayAdapter 进行初始化。然后将该适配器设置为 listview。
  • 是的,所以请查看windrealm.org/tutorials/android/android-listview.php。每个 ListView 项目/部分都需要一个布局...布局将具有看起来像图像、文本视图和按钮的内容。
  • @Danger 还是一针见血。您需要适配器将数据传递到各个列表行(具有布局),然后将其应用于 ListView 本身。

标签: android listview android-fragments android-view android-relativelayout


【解决方案1】:

您应该将 android RecyclerView 与自定义项目视图持有者一起使用,然后您可以创建一个自定义 UI,如您的列表项并将其添加到您的 RecyclerView 看这个例子

https://www.androidhive.info/2016/01/android-working-with-recycler-view/

三个点 以垂直顺序创建具有三个视图的 LinewLayout,并将它们的背景设置为自定义圆角 drwable:

drawable 文件夹中的rounded_view.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <solid android:color="@color/black" />
            <size
                android:width="@dimen/dp_10"
                android:height="@dimen/dp_10" />
        </shape>
    </item>
</layer-list>

在你的主视图 Item xml 文件中添加:

<LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="end"
            android:gravity="center">
                <View
                    android:layout_width="@dimen/dp_10"
                    android:layout_height="@dimen/dp_10"
                    android:background="@drawable/rounded_view"/>
                <View
                    android:layout_margin="@dimen/dp_5"
                    android:layout_width="@dimen/dp_10"
                    android:layout_height="@dimen/dp_10"
                    android:background="@drawable/rounded_view"/>
                <View
                    android:layout_width="@dimen/dp_10"
                    android:layout_height="@dimen/dp_10"
                    android:background="@drawable/rounded_view"/>
        </LinearLayout>

【讨论】:

  • 似乎是一种冗长的编码方式。我可以使用 ListView 做到这一点,但无法在每个上添加 3 点线应用 按钮查看上面的截图。
猜你喜欢
  • 2012-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-30
  • 1970-01-01
相关资源
最近更新 更多