2014-06-13 22 views
-1

我基本上想要訪問我的佈局,以便當用戶單擊當前屏幕上的任何位置時,我可以移動到下一個屏幕。 這是我的xml代碼。Android:我如何在我的課程中使用id(我已經提供了xml)訪問我的主佈局?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:minWidth="25px" 
android:minHeight="25px" 
android:id="@+id/hellolayout"> 
<TextView 
    android:text="WELCOME!" 
    android:textSize="50dp" 
    android:gravity="center" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="0.9" 
    android:id="@+id/textView1" 
    android:layout_centerHorizontal="true" /> 
<ImageView 
    android:src="@drawable/idiotic_smile" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="0.1" 
    android:id="@+id/imageView1" /> 
</LinearLayout> 

在課堂上,'hellolayout'不被識別。有什麼我想錯過的?

LinearLayout l = FindViewById<LinearLayout> (Resource.Id.hellolayout); 
+1

你必須閱讀文檔。 – Raghunandan

+0

我有。問題是,我可以使用id訪問任何按鈕/圖像瀏覽/子佈局,但不能訪問父佈局:如果有人可以幫忙,那麼這將非常棒。我在這裏新建 – yolo101

+0

您按照與按鈕和圖像瀏覽相同的方式初始化線性佈局 – Raghunandan

回答

0

Acessing的佈局應儘可能R.layout.YourLayoutName一樣簡單。加載它使用setContentView(R.layout.YourLayoutName)
更好參考文檔here

相關問題