![](/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.