片段-创建带有图像、文本和 3 个点的列表视图
Fragment- create list view with image ,texts and 3 dots
当用户点击 FULL-TIME 按钮时,我想打开应该显示列表视图的片段,其中包括 image,texts,以及每个视图右端的 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 还是可以通过编程方式创建?请提出建议?
您应该将 android RecyclerView 与自定义项目视图持有者一起使用,然后您可以创建一个自定义 UI 就像您的列表项目并将其添加到您的 RecyclerView
看这个例子
https://www.androidhive.info/2016/01/android-working-with-recycler-view/
三个点
按垂直顺序创建具有三个视图的 LinewLayout,并将它们作为自定义圆形 drwable 的背景设置为:
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>
在您的主视图项目 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>
当用户点击 FULL-TIME 按钮时,我想打开应该显示列表视图的片段,其中包括 image,texts,以及每个视图右端的 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 还是可以通过编程方式创建?请提出建议?
您应该将 android RecyclerView 与自定义项目视图持有者一起使用,然后您可以创建一个自定义 UI 就像您的列表项目并将其添加到您的 RecyclerView 看这个例子
https://www.androidhive.info/2016/01/android-working-with-recycler-view/
三个点 按垂直顺序创建具有三个视图的 LinewLayout,并将它们作为自定义圆形 drwable 的背景设置为:
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>
在您的主视图项目 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>