![](/img/trans.png)
[英]When is onAttachedToWindow called in the Layouting Process
[英]onAttachedToWindow() is not being called
我正在為這樣的FlyOutContainer類創建對象
this.root = (FlyOutContainer) this.getLayoutInflater().inflate(R.layout.activity_sample, null);
在類FlyOutContainer中,我有onAttachedToWindow()
方法
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Log.i("onAttachedToWindow", " occured");
this.menu = this.getChildAt(0);
this.content = this.getChildAt(1);
this.menu.setVisibility(View.GONE);
}
希望當我為this.root
創建對象時應調用此方法,但是永遠不會調用onAttachedWindow()方法。 為什么??
UPDATE1
<com.bibliotheque.android.view.viewgroup.FlyOutContainer xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#444488"
android:orientation="vertical" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toggleMenu"
android:text="@string/home_btn_label" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toggleMenu"
android:text="@string/search_btn_label" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toggleMenu"
android:text="@string/mybooks_btn_label" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toggleMenu"
android:text="@string/contact_btn_label" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toggleMenu"
android:text="@string/about_btn_label" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#888888"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/home"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#888888"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/search_layout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#888888"
android:orientation="vertical" >
<EditText
android:id="@+id/searchInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="text" />
<ListView
android:id="@+id/bookList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
我正在使用FlyOutContainer來實現“滑入”菜單
您是否已實際將視圖添加到布局?
您需要在要包含FlyOutContainer的父對象上調用addView(root)
,或在LayoutInflater
上使用3參數方法:
getLayoutInflater().inflate(R.layout.activity_sample, container, true)
同樣, container
是將包含新視圖的ViewGroup
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.