Android 如何刷新抽屉布局中包含的框架布局内的视图

Android 如何刷新抽屉布局中包含的框架布局内的视图,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,基本上我有一个带按钮的抽屉。单击按钮时,我希望隐藏在FrameLayout中加载的视图(另一个按钮)。 下面是抽屉的XML代码。按钮不包括在其中,因为它是在代码中动态生成的。 我尝试获取frameLayout并使视图无效,但它似乎不起作用。我认为这与它被装入一个片段这一事实有某种联系 任何线索都欢迎!谢谢 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/

基本上我有一个带按钮的抽屉。单击按钮时,我希望隐藏在FrameLayout中加载的视图(另一个按钮)。 下面是抽屉的XML代码。按钮不包括在其中,因为它是在代码中动态生成的。 我尝试获取frameLayout并使视图无效,但它似乎不起作用。我认为这与它被装入一个片段这一事实有某种联系

任何线索都欢迎!谢谢

<android.support.v4.widget.DrawerLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/myDrawer"
   android:layout_width="match_parent"
   android:layout_height="match_parent" >

   <FrameLayout
     android:id="@+id/home_frame"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >

     <include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/home_layout" />
   </FrameLayout>
</android.support.v4.widget.DrawerLayout>

好了,开始工作了。我认为使用FrameLayout有一些隐藏的魔力,但不是。方法完全相同。找到以下解决方案:

        View view;
        if ((view = findViewById(R.id.bottomSet)) != null) {
            view.setVisibility(View.VISIBLE);
            view.invalidate();
        }

请注意,“bottomSet”是在正在导入的FrameLayout中定义的。

您只需隐藏第二个按钮(以编程方式生成的按钮)?实际上不是。以编程方式生成的按钮位于抽屉布局中。它有一个关联的onClick事件,该事件应该隐藏一个位于home\u布局中的按钮。