2012-04-22 89 views
0

我試圖顯示/隱藏一個具體的ImageView,它在FrameLayout內。同時,我也會隱藏或顯示(與此相反,以ImageView),該LinearLayout與ID recents_linear_layout如何在FrameLayout中顯示/隱藏ImageView

<com.android.systemui.recent.RecentsPanelView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/recents_root" 
android:layout_height="match_parent" 
android:layout_width="match_parent"> 

<FrameLayout 
    android:id="@+id/recents_bg_protect" 
    android:background="@drawable/status_bar_recents_background" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:clipToPadding="false" 
    android:clipChildren="false"> 

    <com.android.systemui.recent.RecentsHorizontalScrollView android:id="@+id/recents_container" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_marginRight="@dimen/status_bar_recents_right_glow_margin" 
     android:divider="@null" 
     android:stackFromBottom="true" 
     android:fadingEdge="horizontal" 
     android:scrollbars="none" 
     android:fadingEdgeLength="@dimen/status_bar_recents_fading_edge_length" 
     android:layout_gravity="bottom|left" 
     android:orientation="horizontal" 
     android:clipToPadding="false" 
     android:clipChildren="false"> 

     <LinearLayout android:id="@+id/recents_linear_layout" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:clipToPadding="false" 
      android:clipChildren="false"> 
     </LinearLayout> 


    </com.android.systemui.recent.RecentsHorizontalScrollView> 

**<ImageView android:id="@+id/landscape" 
    android:gravity="center" 
    android:layout_gravity="center" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="0.0dip" 
    android:src="@drawable/landscape_img" 
    android:visibility="gone" />** 

</FrameLayout> 

<include layout="@layout/status_bar_no_recent_apps" 
    android:id="@+id/recents_no_apps" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:visibility="invisible" /> 

</com.android.systemui.recent.RecentsPanelView> 

我的Java代碼,拋出一個NullPointerException,因爲它不能找到ImageView(因爲這是在com.android.systemui.recent.RecentsHorizontalScrollView被執行。這是代碼

mLinearLayout = (LinearLayout) findViewById(R.id.recents_linear_layout); 
    mLinearLayout.setVisibility(mRecent ? LinearLayout.GONE : LinearLayout.VISIBLE); 
mLandScape = (ImageView) findViewById(R.id.landscape); 
mLandScape.setVisibility(mRecent ? View.VISIBLE : View.GONE); 

在此先感謝。

+0

的ImageView的是你必須把它傳遞在某種程度上 – Blundell 2012-04-22 19:25:13

+0

是的,那是你RecentsHorizo​​ntalScrollView的範圍之內我需要的。但我不知道如何檢索ID,使用findViewById方法 編輯:似乎我修好了,編輯主帖 – user809486 2012-04-22 19:27:59

+0

是的,你把它移到範圍。你不應該編輯它,只需在下面回答你自己的問題。 – Blundell 2012-04-22 19:35:43

回答

0

你庫侖d使用((Activity)getContext())。findViewById(R.id.landscape)儘管你應該避免它,因爲不能保證上下文是一個活動。我不明白你爲什麼試圖在這個視圖中隱藏一些視圖。我認爲這是活動的責任。你應該使用回調方法做一些接口來通知活動有關你的事件,然後讓它隱藏圖像視圖。

0

固定 修復程序使舊的佈局和ImageView的一個外部佈局容器作爲孩子的

<com.android.systemui.recent.RecentsHorizontalScrollView android:id="@+id/recents_container" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_marginRight="@dimen/status_bar_recents_right_glow_margin" 
     android:divider="@null" 
     android:stackFromBottom="true" 
     android:fadingEdge="horizontal" 
     android:scrollbars="none" 
     android:fadingEdgeLength="@dimen/status_bar_recents_fading_edge_length" 
     android:layout_gravity="bottom|left" 
     android:orientation="horizontal" 
     android:clipToPadding="false" 
     android:clipChildren="false"> 

     <LinearLayout android:id="@+id/child_container" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:clipToPadding="false" 
      android:clipChildren="false"> 

      <LinearLayout android:id="@+id/recents_linear_layout" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:orientation="horizontal" 
       android:clipToPadding="false" 
       android:clipChildren="false" /> 

     <ImageView android:id="@+id/sense_landscape" 
     android:gravity="center" 
     android:layout_gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="0.0dip" 
     android:src="@drawable/sense_landscape" 
     android:visibility="visible" /> 



     </LinearLayout> 


    </com.android.systemui.recent.RecentsHorizontalScrollView>