簡體   English   中英

如何在FrameLayout中顯示/隱藏ImageView

[英]How to show / hide ImageView in FrameLayout

我試圖顯示/隱藏一個特定的ImageView ,它位於FrameLayout內部。 同時,我要隱藏或顯示(與ImageView相反),ID為最近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);

提前致謝。

您可以使用((Activity)getContext())。findViewById(R.id.landscape),盡管應避免使用它,因為不能保證上下文是活動。 我不明白您為什么要在此視圖中隱藏一些視圖。 我認為這是活動的責任。 您應該使用回調方法建立一些接口,以通知活動有關您的事件,然后使其隱藏圖像視圖。

修復修復了使用外部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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM