0

我有三个用于布局的 xml 文件,例如

  1. activity_behind_left_simple.xml
  2. activity_behind_right_simple.xml
  3. activity_main.xml

我实现了 textViewsactivity_behind_left_simple.xml 并显示了菜单列表。它工作正常。

所以我也做了同样的activity_behind_right_simple.xml事情。

但是,现在应用程序在启动后立即关闭:(

这是为什么?右侧有什么问题? activity_behind_left_simple.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/leftBehindMenuScroll" >

    <LinearLayout style="@style/behindMenuScrollContent"
        android:paddingTop="25dp" >

        <TextView
            style="@style/behindMenuItemTitle"
            android:text="People" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <jp.fureco.IconView 
                android:id="@+id/iconViewItem4"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:textSize="20dp"/>

            <TextView
                android:layout_marginLeft="10dp"
                style="@style/behindMenuItemLabel"
                android:text="Visitor" />

        </LinearLayout>

    </LinearLayout>

</ScrollView>

activity_behind_right_simple.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/rightBehindMenuScroll" >

    <LinearLayout style="@style/behindMenuScrollContent"
        android:paddingTop="25dp" >

        <TextView
            style="@style/behindMenuItemTitle"
            android:text="Messages" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <jp.fureco.IconView 
                android:id="@+id/iconViewItem5"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:textSize="20dp"/>

            <TextView
                android:layout_marginLeft="10dp"
                style="@style/behindMenuItemLabel"
                android:text="Received" />

        </LinearLayout>

    </LinearLayout>

</ScrollView>

SimpleSideDrawer.java

    ....
   public View setLeftBehindContentView(int leftBehindLayout) {
        final View content = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(leftBehindLayout, mLeftBehindBase);

        String[] icons = getResources().getStringArray(R.array.icons);
        IconView iv4 = (IconView) findViewById(R.id.iconViewItem4);
        iv4.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
        iv4.setText(icons[8]);

        IconView iv5 = (IconView) findViewById(R.id.iconViewItem5);
        iv5.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
        iv5.setText(icons[315]);


        mLeftPaddingRect = new Rect(content.getPaddingLeft(), content.getPaddingTop(), content.getPaddingRight(), content.getPaddingBottom());
        mLeftBehindView = content;
        return content;
    }        

    ....

然后,如果我删除这部分,应用程序将不再关闭。
我该如何解决?

IconView iv5 = (IconView) findViewById(R.id.iconViewItem5);
iv5.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
iv5.setText(icons[315]);

MainActivity.java

...
    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    getSize();

    mActionBar = getActionBar();
    mActionBar.hide();


    mNav = new SimpleSideDrawer(this);
    mNav.setLeftBehindContentView(R.layout.activity_behind_left_simple);
    mNav.setRightBehindContentView(R.layout.activity_behind_right_simple);
....

SimpleSideDrawer.java我找到了这个。这有关系吗?

public View setRightBehindContentView(int rightBehindLayout) {
    final View content = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(rightBehindLayout, mRightBehindBase);
    mRightPaddingRect = new Rect(content.getPaddingLeft(), content.getPaddingTop(), content.getPaddingRight(), content.getPaddingBottom());
    mRightBehindView = content;
    return content;
}

第2部分

public View setLeftBehindContentView(int leftBehindLayout) {
    final View content = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(leftBehindLayout, mLeftBehindBase);

    String[] icons = getResources().getStringArray(R.array.icons);

    IconView iv4 = (IconView) findViewById(R.id.iconViewItem4);
    iv4.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
    iv4.setText(icons[25]);

    IconView iv5 = (IconView) findViewById(R.id.iconViewItem5);
    iv5.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
    iv5.setText(icons[26]);

    IconView iv6 = (IconView) findViewById(R.id.iconViewItem6);
    iv6.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
    iv6.setText(icons[117]);        

    mLeftPaddingRect = new Rect(content.getPaddingLeft(), content.getPaddingTop(), content.getPaddingRight(), content.getPaddingBottom());
    mLeftBehindView = content;
    return content;
}
4

2 回答 2

1

它看起来不像你在activity_behind_right_simple.xml任何地方膨胀。据我所知,当您尝试修改 iv5 时,您应该获得 NPE。

编辑:如果您将下面的代码添加到您的主布局中并将其包含ScrollViews在 a 中,FrameLayout这将让它在setContentView().

<include
        layout="@layout/leftScrollView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

<include
        layout="@layout/rightScrollView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
于 2013-08-12T19:45:31.800 回答
1

您需要参考膨胀的布局。尝试使用您在 setLeftBehindContentView 方法中访问的所有视图:

     e.g:  

     IconView iv5 = (IconView) content.findViewById(R.id.iconViewItem5);

注意:我假设与 R.id.iconViewItems 对应的视图位于膨胀的布局文件中。

于 2013-08-13T09:50:49.110 回答