我正在尝试创建一个插件&播放视图。完成的那种成功,但在处理特殊情况时面临困难:在动态添加的ViewGroup中显示片段。
问题步骤:
结果
在动态添加的ViewGroup中,显示ImageView但不显示片段。没有错误。
参考代码:
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CustomViewManager customViewManager = new CustomViewManager(this);
}
}
CustomViewManager.java
public class CustomViewManager {
private CustomViewGroup customViewGroup;
public CustomViewManager(AppCompatActivity context) {
this.context = context;
LayoutInflater inflater = context.getLayoutInflater();
customViewGroup =(CustomViewGroup)inflater.inflate(R.layout.custom_view_layout, null);
FrameLayout.LayoutParams dummyParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
context.addContentView(customViewGroup, dummyParams);
}
}
CustomViewGroup.java - 包含添加ImageView和动态添加片段的逻辑。
注意:
是否可以在动态添加的ViewGroup中显示片段,还是Android中的任何此类限制?