首页 > 解决方案 > 哪些布局元素用于以下类型的布局

问题描述

我当然是新手,Andorid Development并且对基本的东西有一定的了解,,,,,等等....Relative LayoutLinear LayoutIntentFile Handling

我需要构建一个类似于 some 的项目E-commerce app。这是我想要的图像。 Andooid 布局

我如何获得给定的产品视图,就像在博客或其他网站中一样。我必须使用List View吗?

请告诉我必须使用什么来制作“ Add Filter Tags”部分以及如何实现我在图片中显示的内容。

标签: androidandroid-layout

解决方案


下面是将为您的 UI 要求创建骨架的代码。您可以根据需要对其进行修改。

您的 Activity/Fragment xml 将如下所示:

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

    <android.support.constraint.ConstraintLayout
        android:id="@+id/cl_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

    <com.google.android.material.chip.ChipGroup
        android:id="@+id/entry_chip_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/cl_parent">

    </com.google.android.material.chip.ChipGroup>

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/entry_chip_group"

        />
</android.support.constraint.ConstraintLayout>

RecyclerView 的适配器 xml 将如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/iv_product"
        android:layout_width="100dp"
        android:layout_height="match_parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Product Name"
        app:layout_constraintStart_toEndOf="@id/iv_product"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Product Information"
        app:layout_constraintStart_toStartOf="@id/tv_name"
        app:layout_constraintTop_toBottomOf="@id/tv_name" />

    <TextView
        android:id="@+id/tv_more_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="More info"
        app:layout_constraintStart_toStartOf="@id/tv_name"
        app:layout_constraintTop_toBottomOf="@id/tv_info" />

    <TextView
        android:id="@+id/tv_data"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Data"
        app:layout_constraintStart_toStartOf="@id/tv_name"
        app:layout_constraintTop_toBottomOf="@id/tv_more_info" />

    <TextView
        android:id="@+id/tv_tags"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Tags"
        app:layout_constraintStart_toStartOf="@id/tv_name"
        app:layout_constraintTop_toBottomOf="@id/tv_data" />
</android.support.constraint.ConstraintLayout>

你应该使用Chips你的过滤器标签。您可以将它们动态添加到您的chip group. 以下是供参考的链接。

如何使用安卓芯片


推荐阅读