簡體   English   中英

Android中布局內部的動態控制

[英]Dynamic control inside a layout in android

在此處輸入圖片說明 我有一個活動,其中要顯示“文本”,然后顯示該列表下的一些內容。

一些內容可能是圖片,相對布局,視頻控件或線性布局。 取決於從先前活動獲得的數據。

是否可以做到這一點,或者我必須為所有項目制作單獨的布局?

您可以在一種布局中創建所有可能的項目,並根據收到的數據設置可見和消失,在這種情況下,您無需在代碼中創建它們,並且可以在設計模式下預覽活動布局。

您需要這樣的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <FrameLayout
        android:id="@+id/flSpecialContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

    </FrameLayout>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

您可以根據需要將代碼中所需的任何視圖添加到FrameLayout(flSpecialContainer)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM