开发者

Exception when creating a simple, two-pane layout with fragments

I'm attempting to create a simple two panel layout with fragments. This will eventually be built up into something more complicated, but for now开发者_StackOverflow I'm just trying to get two empty panels to show up with different background colors. I'm getting an exception when I try this and I'm not sure why. I've used the example from Google as my guide, found here: http://developer.android.com/guide/topics/fundamentals/fragments.html#Example

Here is my XML file, fragment_signon.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <fragment android:id="@+id/fragmentOptionsPanel" 
        android:layout_width="12dp"
        android:layout_height="match_parent" 
        android:background="@color/black_shadow" />
    <fragment 
        android:id="@+id/fragmentSignOn" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"
        android:background="@color/blue_text" />
</LinearLayout>

Here is my Activity that loads the fragment layout.

public class SignOnFragmentLayout extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.fragment_signon);
    }
}

I get the following exception(s) at runtime:

07-08 00:06:02.310: ERROR/AndroidRuntime(1486): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mfoundry.boa.ui/com.mfoundry.boa.ui.SignOnFragmentLayout}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment

...

07-08 00:06:02.310: ERROR/AndroidRuntime(1486): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment

I'm not sure what I'm doing wrong. I don't want anything to load in the layouts, just to show a panel on the left that is a certain width and then the rest of the screen being another color.


It looks like you need to specify the class attribute for the fragment elements. If you don't want anything to load, then don't load anything in the fragment if it is called from the constructor, like it would be here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜