碎片在android中可见并消失了



我必须开发一个android应用程序。

这里我必须检查值。如果值为Null意味着必须隐藏片段。否则片段是可见的。我该怎么办??

请给我解决这些问题的方法。

 FragmentManager fragmentManager = getFragmentManager();
      FragmentTransaction fragmentTransaction = fragmentManager
              .beginTransaction();
        YouTubePlayerSupportFragment fragment = new YouTubePlayerSupportFragment();
        fragmentTransaction.add(R.id.youtube_fragment, fragment); 
        fragmentTransaction.commit();
       _Video = articlevideo.substring(1);
       fragment.initialize(DeveloperKey.DEVELOPER_KEY, new OnInitializedListener() {

            public void onInitializationSuccess(YouTubePlayer.Provider provider,
                    YouTubePlayer player, boolean wasRestored) {
                if (!wasRestored) {
                    player.cueVideo(_Video);
                }
            }
            @Override
            public void onInitializationFailure(Provider arg0,
                    YouTubeInitializationResult arg1) {
            }
        });


      String vid = "Null";
        if(_Video.equalsIgnoreCase(vid))
        {
      //Gone the fragment      
        }
        else
        {
          //Visible the fragment      
        } 

如何隐藏这些活动上的片段…

我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#414042"
android:orientation="vertical" >
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#414042"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />
     <fragment
    android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
    android:id="@+id/youtube_fragment"
    android:layout_width="match_parent"
    android:layout_below="@+id/title"
    android:layout_height="wrap_content"/>
   <WebView
                android:id="@+id/fullcontent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#414042"
               android:layout_below="@+id/youtube_fragment"
                 />

  </RelativeLayout>

    </RelativeLayout>

如何隐藏片段??请给我一个解决方案吧?

try yourView.setVisibility(View.VISIBLE);

yourView.setVisibility(View.GONE);//这个视图是不可见的,它不占用任何空间用于布局

yourView.setVisibility(View.INVISIBLE);//这个视图是不可见的,但它仍然占用空间的布局目的

最新更新