2011-08-05 52 views
2

我有一個疑問,是否應該在我們的佈局文件中使用strings.xml文件中的所有字符串文本,還是應該我們在佈局文件本身的「字符串文本」中輸入屬性值,如android:text="some text"我們是否應該在Strings.xml中提供字符串值,還是在輸出xml文件本身

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:id="@+id/ll1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <Button android:text="Button" 
    android:id="@+id/butShow" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    </Button> 


</LinearLayout> 

則是罰款給android:text="Button"還是應該使用android:text="@string/btnlabel"

的strings.xml

<resources> 
    <string name="btnLabel">Button</string> 
</resources> 

我們應該指定的strings.xml或只有特定的人所有的字符串文本。

+0

ü可以寫代碼 – Randroid

回答

0

如果您決定將您的應用程序國際化,您將會更好地將所有字符串提取到strings.xml中!那麼你只需要做爲每種語言不同的strings.xml而不是佈局過於

+0

你是怎麼做到的??? – garatu

+0

https://developer.android.com/guide/topics/resources/localization.html – dten

1

check my answer hereOk

尋找到的android.content.res.resources的源代碼和其他一些類之後,顯而易見的是,利用資源和獲取資源通過getResources()是有點昂貴

然而使用getResources()有它的優點

  • 它可以幫助你外部化的資源

對於任何類型的資源,您可以指定默認和多個替代資源上地點屏幕深度/分辨率也許取決於...


以兩種方式
相關問題