可见并在android中删除了片段

时间:2013-05-06 13:45:04

标签: android android-fragments fragment

我必须开发一个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>

我怎样才能隐藏片段???请给我解决方案???

1 个答案:

答案 0 :(得分:1)

尝试yourView.setVisibility(View.VISIBLE);

yourView.setVisibility(View.GONE); //此视图不可见,并且不需要任何空间用于布局目的

yourView.setVisibility(View.INVISIBLE); //此视图不可见,但仍会占用空间以进行布局。