【发布时间】:2012-04-22 19:20:02
【问题描述】:
我试图显示/隐藏一个特定的ImageView,它位于FrameLayout 内。同时,我要隐藏或显示(与ImageView相反),id为recents_linear_layout
LinearLayout
<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);
提前致谢。
【问题讨论】:
-
ImageView 超出了您的RecentsHorizontalScrollView 的范围,您必须以某种方式传递它
-
是的,这就是我需要的。但我不知道如何使用 findViewById 方法检索 ID 编辑:好像我修复了它,编辑了主帖
-
是的,您已将其移入范围。您不应该真正编辑它,只需在下面回答您自己的问题。
-
我会回答,但由于声誉,我需要 8 小时 :D
标签: java android imageview android-linearlayout android-framelayout