我已經淘汰互聯網無濟於事。我正在嘗試爲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);
}
謝謝!
它編譯?我發現你錯過了一個' LinearLayout>',但我保證你沒有複製它。 – Sam
你不小心導入了'android.R'嗎? – trichner