TableLayout中的导航抽屉渲染错误

时间:2016-03-30 20:16:19

标签: android xml android-layout navigation-drawer android-navigation-drawer

我想在我的应用程序中的每个布局上插入抽屉。 这是我的xml代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawerActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/tableLayoutActivity"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:padding="5dp"
            android:stretchColumns="*">
            <!--   <TableRow android:id="@+id/tableRow0"
                   android:layout_height="wrap_content"
                   android:layout_width="match_parent">
               </TableRow>-->


            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#fff">

                <ScrollView
                    android:id="@+id/queryScrollView"
                    android:layout_width="match_parent"
                    android:layout_span="2"
                    android:padding="5dp">

                    <TableLayout
                        android:id="@+id/queryTableLayoutActivity"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="5dp"
                        android:stretchColumns="*"></TableLayout>
                </ScrollView>
            </TableRow>

        </TableLayout>

    <ListView
        android:id="@+id/navList"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:background="#ffeeeeee"
        android:choiceMode="singleChoice" />
</android.support.v4.widget.DrawerLayout>

我在运行应用程序时遇到此错误(Stacktrace)

Process: com.teamtreehouse.oslist, PID: 2217
                                                                    java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
                                                                        at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:814)
                                                                        at android.view.View.measure(View.java:18788)
                                                                       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
                                                                        at android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:461)
                                                                        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
                                                                        at android.widget.TableLayout.measureVertical(TableLayout.java:473)
                                                                        at android.widget.TableLayout.onMeasure(TableLayout.java:436)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1283)
                                                                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                        at android.widget.ScrollView.onMeasure(ScrollView.java:340)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.widget.TableRow.measureChildBeforeLayout(TableRow.java:222)
                                                                        at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1112)
                                                                        at android.widget.TableRow.onMeasure(TableRow.java:113)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
                                                                        at android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:461)
                                                                        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
                                                                        at android.widget.TableLayout.measureVertical(TableLayout.java:473)
                                                                        at android.widget.TableLayout.onMeasure(TableLayout.java:436)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:851)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
                                                                        at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1112)
                                                                        at android.widget.LinearLayout.onMeasure(LinearLayout.java:632)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                        at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:453)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
                                                                        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
                                                                        at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                                                                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                        at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
                                                                        at android.view.View.measure(View.java:18788)
                                                                        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
                                                                        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
                                                                        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
                                                                        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
                                                                        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
                                                                        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                        at android.view.Choreographer.doCallbacks(Choreograp

Similar question but not exact solution required for me

我在这里缺少什么。我无法将抽屉插入布局。除了提到确切的高度和宽度之外,是否有永久的解决方案。

1 个答案:

答案 0 :(得分:1)

必须使用MeasureSpec.EXACTLY 测量DrawerLayout。 你必须把match_parent放到高度。