在android中可见并消失了片段
我必须开发一个单安卓应用程序 在这里,我必须检查值。如果值为Null,则意味着必须隐藏片段。否则,片段将可见。我该怎么办 请给我这些问题的解决办法在android中可见并消失了片段,android,android-fragments,fragment,Android,Android Fragments,Fragment,我必须开发一个单安卓应用程序 在这里,我必须检查值。如果值为Null,则意味着必须隐藏片段。否则,片段将可见。我该怎么办 请给我这些问题的解决办法 FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); YouTubePlay
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>
我怎样才能隐藏碎片???请给我解决方案???试试
yourView.setVisibility(View.VISIBLE)代码>
yourView.setVisibility(View.GONE)代码>//此视图不可见,并且不占用任何空间用于布局
和yourView.setVisibility(View.INVISIBLE)代码>//此视图不可见,但仍会占用空间用于布局。String vid=“Null”;如果(_Video.equalsIgnoreCase(vid)){fragment.setVisibility(View.GONE);}否则{fragment.setVisibility(View.VISIBLE);}意味着我在这些行上遇到以下错误:方法setVisibility(int)类型YouTubePlayerSupportFragmenti未定义。我已为这些片段创建了单独的布局,并为该布局创建了GONE和VISIBLE functionlaity。现在我明白了,谢谢。