2010-08-19 32 views
2

我正在創建一個貨幣匯率應用程序來學習Android。該應用程序將列出一個列表中的所有匯率,他們每個人都有這樣的佈局(必需):如何複製視圖的所有屬性?

<TableRow> 
    <ImageView> 
     [properties for the Flag image here] 
    </ImageView> 
    <TableLayout> 
     <TableRow> 
      <TextView> [Buying] </TextView> 
      <TextView> [Buying Rate] </TextView> 
     </TableRow> 
     <TableRow> 
      <TextView> [Transfer] </TextView> 
      <TextView> [Transfer Rate] </TextView> 
     </TableRow> 
     <TableRow> 
      <TextView> [Selling] </TextView> 
      <TextView> [Selling Rate] </TextView> 
     </TableRow> 
    </TableLayout> 
</TableRow> 

要列出匯率,我有以下方法中,所有貨幣:

 
- Design the layout for one currency (let’s choose EUR as first currency) 
- Generate the layout for all other currencies automatically by: 
1. Copy all properties of the EUR-layout into the new currency layout 
2. Modify some properties of new currency layout like: ID, Rates … 
3. Repeat steps 1,2 for all sub-layout of the new currency layout 

但我不知道如何編碼第1步,所以我做了很多谷歌有關:「android複製視圖」「android複製屬性」「android複製視圖」「android克隆視圖」「java克隆對象」...。但仍然沒有解決辦法。

所以,我的問題是:如何複製視圖的所有屬性?

回答

4

兩種方法: 看LayoutInflater膨脹從XML sublayout或在這裏使用一個ListView(實際上也使用LayoutInflater到底。)

搜索LayoutInflater對SO樣品,即 What does LayoutInflater in Android do?

+1

謝謝Mathias, 我已經根據你的關鍵字做了一些閱讀,並解決了這個問題:創建一個自定義列表視圖。這裏有一些有用的參考,我希望他們可以幫助像我這樣的一些初學者: - 教程 - 創建自定義列表視圖: http://www.softwarepassion.com/android-series-custom-listview-items-和適配器/ - 創建視圖,這是泰勒對我們的需要: 「專業Android 2應用程序開發(Wrox程序員到程序員)」 - 第4章 - 創建新視圖 – hungson175 2010-08-22 19:16:07

+0

您的答案幫助指向我在右邊方向。 [我做了一個例子](http://stackoverflow.com/a/41500409/3681880)來說明如何用'LayoutInflater'複製一個視圖的所有屬性。 – Suragch 2017-01-06 06:53:25

相關問題