0

我试图特别显示/隐藏 a ImageView,它在 a 内FrameLayout。同时,我要隐藏或显示(相反ImageView),LinearLayoutid为recents_linear_layout

<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);

提前致谢。

4

2 回答 2

0

你可以使用 ((Activity)getContext()).findViewById(R.id.landscape) 虽然你应该避免它,因为不能保证上下文是一个活动。我不明白你为什么要在这个视图中隐藏一些视图。我认为这是活动的责任。您应该使用回调方法创建一些接口来通知活动有关您的事件,然后让它隐藏图像视图。

于 2012-04-22T19:32:10.840 回答
0

FIXED 修复正在制作一个外部布局容器,其中旧 Layout 和 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>
于 2012-04-23T13:41:00.007 回答