简体   繁体   English

如何在另一个Linearlayout中创建带有特定视图的Linearlayout作为项目(任务)?

[英]How to create a Linearlayout with specific views as an item (Task) inside another Linearlayout?

A week ago I started my todo-list app project and I am learning a lot. 一周前,我启动了待办事项清单应用程序项目,并且学到了很多东西。 I'd like to know about a specific case I couldn't find. 我想知道我找不到的特定案例。

The case: I try to create a "layout-item" of type Linearlayout as a task with specific views inside of it like "Task name, Task description, time, delete button" inside another Linearlayout. 案例:我尝试创建一个Linearlayout类型的“ layout-item”作为任务,并在其中包含特定视图,例如在另一个Linearlayout中创建“任务名称,任务描述,时间,删除按钮”。 But here is the thing, the views of the first Linearlayout are all having a specific position inside of it. 但这就是问题,第一个Linearlayout的视图在其中都有特定的位置。 I want to keep the positions of the views. 我想保持观点的立场。 How do I create this kind of Layout as an item? 如何将这种布局作为项目创建?

Another short question: When I create this Layout how do I delete it programmatically? 另一个简短的问题:创建此版式时,如何以编程方式将其删除?

Here you can find my created design and how exactly the "layout-item" (tasks) should look like 在这里,您可以找到我创建的设计以及“布局项目”(任务)的外观如何 应用设计预览

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="#eeeeee"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/fira_sans_extra_condensed_semibold"
                    android:text="Task1"
                    android:textColor="@color/Task_Name"
                    android:textSize="16sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textView11"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/fira_sans_condensed_light"
                    android:text="Description1 - I want to create a great todo list app :)"
                    android:textSize="14sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <TextView
                android:id="@+id/textView111"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:fontFamily="@font/fira_sans_condensed_light"
                android:gravity="end"
                android:text="9am"
                android:textStyle="bold" />

            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="0dp"
                android:layout_height="34dp"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="5dp"
                android:layout_weight="1"
                android:background="@null"
                android:contentDescription="@string/Delete_Icon"
                android:tint="@color/Task_Name"
                app:srcCompat="@android:drawable/ic_menu_delete" />

    </LinearLayout>

Ahmed is correct, you would use a recycler and create a view that had: Task name, Task description, time, delete button. Ahmed是正确的,您将使用回收站并创建具有以下视图:任务名称,任务描述,时间,删除按钮。 You then can remove and add items by editing the array that contains your items. 然后,您可以通过编辑包含项目的数组来删除和添加项目。

Here is a simple recycler example: Simple Android RecyclerView example 这是一个简单的回收站示例: 简单的Android RecyclerView示例

You can use a RecyclerView as described here: 您可以按照以下说明使用RecyclerView:

https://developer.android.com/guide/topics/ui/layout/recyclerview https://developer.android.com/guide/topics/ui/layout/recyclerview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用ImageView创建LinearLayout并将其以编程方式添加到另一个LinearLayout - How to create LinearLayout with ImageView and add it to another LinearLayout programatically Append 以编程方式在另一个 LinearLayout 中的一个 LinearLayout - Append a LinearLayout inside another LinearLayout programmatically 如何在另一个LinearLayout之后添加LinearLayout? - How to add a LinearLayout after another LinearLayout? 将视图添加到另一行(另一个LinearLayout)? - Adding views to another line (another LinearLayout)? LinearLayout 和 NestedScrollView 中的 RecyclerView - 如何滚动到某个位置的项目顶部? - RecyclerView inside LinearLayout and NestedScrollView - How to scroll to top of item on a certain position? 在 LinearLayout 中动态设置视图的宽度(权重) - Dynamically set the widths (weights) of Views inside a LinearLayout 如何删除 LinearLayout 内的 ImageView - How to remove a ImageView inside of LinearLayout Android如何从代码向另一个LinearLayout添加Linearlayout - Android how to add a Linearlayout to another LinearLayout from code 如何在LinearLayout中消除视图之间的空间 - How to get rid of space between Views in LinearLayout 如何以相反的顺序将子视图添加到 LinearLayout? - How to add child views to a LinearLayout in reverse order?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM