如何在特定片段的Activity中隐藏<include>布局

时间:2018-04-27 11:21:56

标签: android

我在活动中有一个应用品牌页脚活动我有三个片段 第一个片段是注册表 第二个片段是otp 第三个片段是关键片段 该活动类似于所有片段仅片段的更改 ,现在我想隐藏第一个片段的包含布局?

活动xml代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:ignore="MissingPrefix">
         <RelativeLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:id="@+id/relativeLayout6">

                <RelativeLayout
                       android:layout_width="match_parent"
                       android:layout_height="wrap_content"
                       android:layout_alignParentStart="true"
                       android:gravity="center_horizontal|center_vertical"
                       android:layout_marginTop="@dimen/_46sdp"
                    android:id="@+id/relativeLayout10">

                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:baselineAligned="true"
                          android:orientation="vertical">

                          <ImageView
                             android:layout_width="40dp"
                             android:layout_height="40dp"
                             android:layout_gravity="center"
                             android:src="@drawable/ic_feye_logo_small" />

                          <TextView
                              fontPath="fonts/Helvetica.otf"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:gravity="center"
                              android:text="@string/signin"
                              android:textColor="#3f5abd"
                              android:textSize="20sp" />
                       </LinearLayout>
                </RelativeLayout>

             <RelativeLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_alignParentStart="true"
                 android:layout_below="@+id/relativeLayout10"
                 android:layout_gravity="center"
                 android:gravity="center"
                 android:layout_marginTop="@dimen/_4sdp"
                 android:id="@+id/relativeLayout11">

                 <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_gravity="center"
                     android:gravity="center">

                     <ImageView
                         android:id="@+id/dotimgone"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_margin="@dimen/_1sdp"
                         android:src="@drawable/selected_dot_item" />

                     <ImageView
                         android:id="@+id/dotimgtwo"

                         android:layout_width="wrap_content"

                         android:layout_height="wrap_content"
                         android:layout_margin="@dimen/_1sdp"
                         android:src="@drawable/non_selected_item" />

                     <ImageView
                         android:id="@+id/dotimgthree"

                         android:layout_width="wrap_content"

                         android:layout_height="wrap_content"
                         android:layout_margin="@dimen/_1sdp"
                         android:src="@drawable/non_selected_item" />

                     <ImageView
                         android:id="@+id/dotimgfour"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_margin="@dimen/_1sdp"
                         android:src="@drawable/non_selected_item" />
                 </LinearLayout>
             </RelativeLayout>

             <RelativeLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_below="@+id/relativeLayout11"
                 android:layout_centerHorizontal="true"
                 android:layout_marginTop="4dp"
                 android:layout_weight="1"
                 android:orientation="vertical">


                 <RelativeLayout
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
                     android:orientation="vertical">
                     <RelativeLayout
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:orientation="vertical"
                         android:id="@+id/relativeshadowparent">

                         <com.planfisheye.fisheye.views.ShadowLayout
                             android:layout_width="match_parent"
                             android:layout_height="wrap_content"
                             android:focusable="true"
                             android:focusableInTouchMode="true"
                             android:orientation="vertical"
                             app:sl_cornerRadius="@dimen/_15sdp"
                             app:sl_shadowRadius="@dimen/_10sdp"
                             android:id="@+id/shadowLayout">

                             <LinearLayout
                                 android:id="@+id/fragmentlayout"
                                 android:layout_width="match_parent"
                                 android:layout_height="wrap_content"
                                 android:orientation="vertical"
                                 android:visibility="visible">
                             </LinearLayout>


                             <!--<LinearLayout-->
                             <!--android:visibility="gone"-->
                             <!--android:id="@+id/otplayout"-->

                             <!--android:layout_width="match_parent"-->
                             <!--android:layout_height="wrap_content">-->
                             <!--<include layout="@layout/otp_layout" />-->
                             <!--</LinearLayout>-->

                             <!--<LinearLayout-->
                             <!--android:visibility="gone"-->
                             <!--android:id="@+id/securityqlayout"-->

                             <!--android:layout_width="match_parent"-->
                             <!--android:layout_height="wrap_content">-->
                             <!--<include layout="@layout/security_question_layout" />-->
                             <!--</LinearLayout>-->

                             <!--<LinearLayout-->
                             <!--android:visibility="gone"-->
                             <!--android:id="@+id/masterlayout"-->

                             <!--android:layout_width="match_parent"-->
                             <!--android:layout_height="wrap_content">-->
                             <!--<include layout="@layout/master_key_layout" />-->
                             <!--</LinearLayout>-->
                         </com.planfisheye.fisheye.views.ShadowLayout>

                     </RelativeLayout>

                 </RelativeLayout>
             </RelativeLayout>
             <include
                 android:id="@+id/support_layout"
                 layout="@layout/logo_layout"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_alignParentEnd="true"
                 android:layout_alignParentBottom="true"
                 android:layout_marginBottom="@dimen/_2sdp">
             </include>
    </RelativeLayout>

</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

您可以获取该片段的Instanceof并设置可见性,即隐藏/显示您要隐藏的布局  if(yourCurrentfragment instanceof first fragment){ findViewById(R.id.support_layout).setVisibility(View.GONE); }

答案 1 :(得分:0)

尝试以下代码:

View supportLayout = findViewById(R.id.support_layout);// write this in your activity and dont forget to make supportLayout public

((YourActivity)getActivity()).supportLayout.setVisibility(View.GONE);
相关问题