2014-03-07 2 views
2

이 문제에 대한 많은 연구가 있었지만 원하는 답을 얻지 못했습니다. 그래서 서버에서 문자열을 가져 오는 응용 프로그램이 있습니다. 일련의 문자열은 XML 형식입니다. 여기 서버에서 XML 레이아웃로드 (안드로이드)

은 (당신이 볼 수 있듯이 그것은 레이아웃입니다) 나는 서버에서 얻을 것이다 무엇의 예입니다

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

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/number_ref" /> 
    <EditText 
     android:id="@+id/etTxtNumber" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/subject_ref" /> 
    <EditText 
     android:id="@+id/etTxtSubject" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/body_ref" /> 
    <EditText 
     android:id="@+id/etTxtBody" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" /> 
    <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 
      <Button 
       android:id="@+id/btnTxtSave" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/save_ref"/> 
      <Button 
       android:id="@+id/btnTxtSend" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/send_ref"/> 
      <Button 
       android:id="@+id/btnTxtClose" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/close_ref"/> 
    </LinearLayout> 

</LinearLayout> 

이 서버에서 업로드됩니다 어떤 XML 파일에 따라 변경됩니다. 내 문제는 어떻게 이러한 일련의 문자열을 레이아웃에 구현하고 활동의 레이아웃으로로드 할 수 있습니다. 나는 그것을 장치의 sdcard에 xml 파일로 저장하고 레이아웃으로로드하려고 생각하고 있었지만 실행 한 후에 코드를 다시 컴파일 할 수는 없다고 생각합니다. 어떤 제안? 고맙습니다.

답변

5

Android documentation에서 설명했듯이 레이아웃 xml 파일은 런타임에 사용되지 않습니다. 컴파일시 이진 코드로 컴파일됩니다. 따라서 XML을 Layout으로 직접로드 할 수는 없습니다.

xml을 읽고 해석하고 Android API 메소드를 사용하여 해당 View를 만드는 코드를 작성해야합니다.

+0

거기에 대한 라이브러리가 거기에 있습니까? – cuddlecheek

관련 문제