我已经将一个动态生成的FrameLayout添加到反应原生视图。 Framelayout正在显示。但是当我向视图添加一个片段时,没有任何显示。react-native add fragment to view is not showing
这里是代码的一部分:
public FrameLayout createViewInstance(ThemedReactContext context) {
Fragment fragment = MapFragment.newInstance(mapKey);
FrameLayout view = new FrameLayout(context);
view.setWillNotDraw(false);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
view.setLayoutParams(lp);
view.setId(View.generateViewId());
view.setBackgroundColor(Color.parseColor("#1FFDDB"));
FragmentActivity activity = MainActivity.getFragmentActivity();
FragmentManager fragmentManager = activity.getSupportFragmentManager();
fragmentManager.beginTransaction().remove(fragment).commit();
fragmentManager.executePendingTransactions();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(0, fragment);
fragmentTransaction.show(fragment);
fragmentTransaction.attach(fragment);
fragmentTransaction.commit();
fragmentManager.executePendingTransactions();
return view;
}
当我添加一个TextView到视图它显示:
// add a textfield to the view
TextView textView1 = new TextView(context);
textView1.setText("Android");
textView1.setTextSize(30);
textView1.setGravity(Gravity.CENTER);
view.setVisibility(View.VISIBLE);
view.addView(textView1);
所以与碎片的问题。 任何想法为什么片段不显示?
http://stackoverflow.com/questions/34410559/how-do-we-get-an-android-fragment-to-show-up-in-react-native – Danieboy
我已经实现它像解释在stackoverflow/34410559。但仍然没有显示出来。 –
我替换了fragmentTransaction.add(0,fragment);与fragmentTransaction.add(view.getId(),fragment);但仍然是相同的问题(没有显示) –