2012-06-25 38 views
2

我已經淘汰互聯網無濟於事。我正在嘗試爲textview設置字體。它在我的main.xml文件中的自己的LinearLayout中。當我在OnCreate中編寫代碼時,它找不到id或父線性佈局。下面的代碼:findViewById - 嵌套的LinearLayouts,沒有找到我的ID - Android

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/background" 
    android:orientation="vertical" 
    android:weightSum="10.0" > 

    <LinearLayout 
     android:id="@+id/map_message_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1.0" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/map_message" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="10dp" 
      android:gravity="center_horizontal" 
      android:text="@string/diagram" /> 

    </LinearLayout> 

而下面onCreate方法:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    LinearLayout = (LinearLayout) this.findViewById(R.id.map_message_layout) 
    TextView maptxt = (TextView) findViewById(R.id.map_message); 
    Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/MuseoSans_100.otf"); 
    maptxt.setTypeface(typeFace); 
} 

謝謝!

+1

它編譯?我發現你錯過了一個'',但我保證你沒有複製它。 – Sam

+0

你不小心導入了'android.R'嗎? – trichner

回答

2

您是否嘗試過清潔您的程序?我有一些奇怪的事情發生之前,並解決了我的問題。不知道是否在這種情況下。

+0

我其實是在錯誤的java文件o_O。在XCode之後,我仍然不是Eclipse的粉絲。哎呦。我還必須清理一下代碼,但我明白了。感謝大家。 –

+0

大聲笑,我已經在這裏或那裏做了幾個定時器。我不介意月食,但我可以在幾個方面看到改善的空間。總體來說,雖然我不介意。 –