我正在使用 Facebook 等滑动菜单构建 Android 应用程序,但ViewGroup
无法正常工作。它在我运行 4.1 的手机上运行良好,但是当我尝试在运行 2.3 的模拟器上运行我的代码时,mContent = (FrameLayout) findViewById(R.id.animation_layout_content);
这条线总是返回null
;但是,mSidebar
正确返回视图。如果有人帮助解决这个问题,我将不胜感激。谢谢!
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_singlepane_empty);
if (getIntent().hasExtra(Intent.EXTRA_TITLE)) {
setTitle(getIntent().getStringExtra(Intent.EXTRA_TITLE));
}
final String customTitle = getIntent().getStringExtra(Intent.EXTRA_TITLE);
setTitle(customTitle != null ? customTitle : getTitle());
if (savedInstanceState == null) {
mFragment = onCreatePane();
mFragment.setArguments(intentToFragmentArguments(getIntent()));
getSupportFragmentManager().beginTransaction()
.add(R.id.animation_layout_content, mFragment, "single_pane")
.commit();
} else {
mFragment = getSupportFragmentManager().findFragmentByTag("single_pane");
}
mLayout = (AnimationLayout) findViewById(R.id.animation_layout);
mLayout.setListener(this);
}
layout.activity_singlepane_empty
<com.oldroid.apps.planit.util.AnimationLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/animation_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="@layout/menu_sidebar" />
<FrameLayout
android:id="@id/animation_layout_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
AnimationLayout
@Override
public void onFinishInflate() {
super.onFinishInflate();
mContent = (FrameLayout) findViewById(R.id.animation_layout_content);
mSidebar = findViewById(R.id.animation_layout_sidebar);
if (mSidebar == null) {
throw new NullPointerException("no view id = animation_sidebar");
}
if (mContent == null) {
throw new NullPointerException("no view id = animation_content");
}
mOpenListener = new OpenListener(mSidebar, mContent);
mCloseListener = new CloseListener(mSidebar, mContent);
}