![](/img/trans.png)
[英]How to create LinearLayout with ImageView and add it to another LinearLayout programatically
[英]How to create a Linearlayout with specific views as an item (Task) inside another Linearlayout?
一周前,我启动了待办事项清单应用程序项目,并且学到了很多东西。 我想知道我找不到的特定案例。
案例:我尝试创建一个Linearlayout类型的“ layout-item”作为任务,并在其中包含特定视图,例如在另一个Linearlayout中创建“任务名称,任务描述,时间,删除按钮”。 但这就是问题,第一个Linearlayout的视图在其中都有特定的位置。 我想保持观点的立场。 如何将这种布局作为项目创建?
另一个简短的问题:创建此版式时,如何以编程方式将其删除?
在这里,您可以找到我创建的设计以及“布局项目”(任务)的外观如何
<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是正确的,您将使用回收站并创建具有以下视图:任务名称,任务描述,时间,删除按钮。 然后,您可以通过编辑包含项目的数组来删除和添加项目。
这是一个简单的回收站示例: 简单的Android RecyclerView示例
您可以按照以下说明使用RecyclerView:
https://developer.android.com/guide/topics/ui/layout/recyclerview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.