我正在尝试向活动添加片段,并且应用程序一直拒绝膨胀或添加片段布局。该应用程序没有崩溃或任何东西,只是一个空白的白色屏幕属于活动
这是活动代码:
public class MovieDetail extends ActionBarActivity {
String Tag = "TAG";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_detail);
BlankFragment fragment = new BlankFragment();
getSupportFragmentManager().beginTransaction().add(fragment, Tag).commit();
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
这是片段类
public class BlankFragment extends Fragment {
public BlankFragment() {
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_blank, container, false);
return root;
}
用于布局
活动xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/weather_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ahmad.popularmovies01.Activities.MovieDetail"
tools:ignore="MergeRootFrame"/>
和片段代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/baseLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
... etc
答案 0 :(得分:0)
getSupportFragmentManager().beginTransaction().
add(0,fragment, Tag).commit();
与
相同getSupportFragmentManager().beginTransaction().
add( fragment,Tag).commit();
此处您的ID为0,因此它刚刚添加到“活动”中,但未与任何视图绑定。