Android TableLayout Error

家住魔仙堡 提交于 2020-01-03 00:54:25

问题


I have made TableLayout. In there statically define table row & if i put Button , it throw error.It may be the small error, i spend more time, but could find out the solution...

Here this is my code..

    <ScrollView android:layout_width="fill_parent"  android:scrollbarStyle="outsideInset" android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb" android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track" android:scrollbarSize="5dp" android:scrollbarFadeDuration="0" android:fillViewport="true" android:layout_height="wrap_content" android:id="@+id/scrollView1" android:layout_weight="1" android:scrollbars="vertical">
    <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="328dp">
        <HorizontalScrollView android:id="@+id/horizontalScrollView1" android:layout_width="fill_parent" android:layout_height="wrap_content" >
          <TableLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:id="@+id/tableLayout1">

            <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dp">
                <TextView android:text="TextView" 
                          android:id="@+id/thTopConer" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:textStyle="bold"
                          android:visibility="invisible"
                          android:layout_width="90dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <TextView android:text="Qty" 
                          android:id="@+id/thQty" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:textStyle="bold"
                          android:layout_width="60dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <TextView android:text="Value" 
                          android:id="@+id/thValue" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:textStyle="bold"
                          android:layout_width="90dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <TextView android:text="Volum" 
                          android:id="@+id/thVolume" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:textStyle="bold"
                          android:layout_width="50dp" 
                          android:layout_height="wrap_content">
                </TextView>


            </TableRow>

            <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dp">
                <TextView android:text="Target" 
                          android:id="@+id/thTarget" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:textStyle="bold"
                          android:layout_width="90dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <TextView android:text="0.00" 
                          android:id="@+id/dtargetQty" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:layout_width="60dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <TextView android:text="0.00" 
                          android:id="@+id/dTargValue" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:layout_width="90dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <TextView android:text="0.00" 
                          android:id="@+id/dTargVolume" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:layout_width="50dp" 
                          android:layout_height="wrap_content">
                </TextView>

            </TableRow>

            <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dp">
                    <TextView android:text="Sales" 
                          android:id="@+id/thSale" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:textStyle="bold"
                          android:layout_width="90dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <TextView android:text="0.00" 
                          android:id="@+id/dSaleQty" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:layout_width="60dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <TextView android:text="0.00" 
                          android:id="@+id/dSaleValue" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:layout_width="90dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <TextView android:text="0.00" 
                          android:id="@+id/dSaleVolume" 
                          android:typeface="serif"
                          android:textColor="@color/black"
                          android:layout_width="50dp" 
                          android:layout_height="wrap_content">
                </TextView>

                <Button android:id="@+id/btnDaSale"
                        android:text="S"
                        android:paddingLeft="10dp" 
                        android:paddingRight="10dp"
                        android:background="@drawable/btn_yellow" 
                        android:textColor="#ffffff"
                        android:layout_marginLeft="2dp"
                        android:layout_marginRight="10dp">
                </Button>
            </TableRow>

        </TableLayout>
        </HorizontalScrollView>
    </LinearLayout>
</ScrollView>

If I remove the Button, its ok woking fine. problem with Button.

Error message:

     02-28 16:35:40.187: ERROR/AndroidRuntime(3963): FATAL EXCEPTION: main
02-28 16:35:40.187: ERROR/AndroidRuntime(3963): java.lang.StackOverflowError
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.text.Styled.measureText(Styled.java:461)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.text.Layout.measureText(Layout.java:1686)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.text.Layout.getLineMax(Layout.java:720)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.text.Layout.draw(Layout.java:371)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.text.BoringLayout.draw(BoringLayout.java:396)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.widget.TextView.onDraw(TextView.java:4090)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6790)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1680)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6896)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.widget.FrameLayout.draw(FrameLayout.java:383)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1680)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6896)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.widget.FrameLayout.draw(FrameLayout.java:383)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1680)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6793)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1680)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6793)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.widget.FrameLayout.draw(FrameLayout.java:383)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1680)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6793)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1680)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6793)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.widget.FrameLayout.draw(FrameLayout.java:383)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1680)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6793)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.widget.FrameLayout.draw(FrameLayout.java:383)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1680)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6793)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.widget.FrameLayout.draw(FrameLayout.java:383)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1680)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.drawChild(ViewGroup.java:1678)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1407)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.View.draw(View.java:6793)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.widget.FrameLayout.draw(FrameLayout.java:383)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1922)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewRoot.draw(ViewRoot.java:1438)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1194)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1758)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.os.Handler.dispatchMessage(Handler.java:130)
02-28 16:35:40.187: ERROR/AndroidRuntime(3963):     at android.os.Looper.loop(Looper.ja

This is my image of screen :

This is my btn_yellow.xml file

         <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <solid
                android:color="#f3ae1b" />
            <stroke
                android:width="1dp"
                android:color="#bb6008" />
            <corners
                android:radius="8dp" />
            <padding
                android:left="2dp"
                android:top="2dp"
                android:right="2dp"
                android:bottom="2dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient
                android:startColor="#f3ae1b"
                android:endColor="#bb6008"
                android:angle="270" />
            <stroke
                android:width="1dp"
                android:color="#bb6008" />
            <corners
                android:radius="7dp" />
            <padding
                android:left="2dp"
                android:top="2dp"
                android:right="2dp"
                android:bottom="2dp" />
        </shape>
    </item>
</selector>

Please anybody help me out from this issue..


回答1:


Check android:background="@drawable/btn_yellow" in Button. If btn_yellow a xml file - check you don't use @drawable/btn_yellow in this xml(cycling reference)




回答2:


the first node needs to contain:

xmlns:android="http://schemas.android.com/apk/res/android"


来源:https://stackoverflow.com/questions/9480972/android-tablelayout-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!