Rows don't render properly in Android Layout. Buttons seem to be the problem

∥☆過路亽.° 提交于 2019-12-02 09:35:44

Are you sure that you added the drawables @calbuttonbluesquare and clearbuttonbluesquare to your list? Also, they should be in a supported format? Try just putting each button on it's own view as a test, to make sure it's showing up right first.

I think you either need to

  1. Set your TableLayout's layout_height and layout_width to fill_parent, or
  2. Wrap the TableLayout inside a ScrollView.

I might be wrong since I'm not very familiar with TableLayouts, but these would be my guesses.

I am usure of what made my XML file work properly... however, the use of DIP as mesure instead of pixels was what seemed to make the difference... The modified code for inspection is posted here. I was going to attach an screenshot of the final product, I have no screenshot of the not-working version, but my reputation is not high enough to do it.

Code:

        <TableRow android:layout_height="fill_parent" android:layout_width="wrap_content" android:id="@+id/fatRow" >
            <TextView android:layout_column="0" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/textView1" android:layout_width="wrap_content" android:text="fat" android:layout_gravity="center_vertical|right" android:gravity="right" android:layout_marginRight="5dip" android:textColor="#FFFFFF"></TextView>
            <EditText android:layout_column="1" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="5dip" android:hint="fat" android:gravity="right" android:id="@+id/fatEditText" android:inputType="numberDecimal"></EditText>
        </TableRow>

        <TableRow android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/carboRow">
            <TextView android:layout_column="0" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/textView3" android:layout_width="wrap_content" android:text="carbo" android:layout_gravity="center_vertical|right" android:gravity="right" android:layout_marginRight="5dip" android:textColor="#FFFFFF"></TextView>
            <EditText android:layout_column="1" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="5dip" android:hint="carbo" android:gravity="right" android:id="@+id/carboEditText" android:inputType="numberDecimal"></EditText>
        </TableRow>

        <TableRow android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/fiberRow">
            <TextView android:layout_column="0" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/textView4" android:layout_width="wrap_content" android:text="fiber" android:layout_gravity="center_vertical|right" android:gravity="right" android:layout_marginRight="5dip" android:textColor="#FFFFFF"></TextView>
            <EditText android:layout_column="1" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="5dip" android:hint="fiber" android:gravity="right" android:id="@+id/fiberEditText" android:inputType="numberDecimal"></EditText>
        </TableRow>

        <TableRow android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/proteinRow">
            <TextView android:layout_column="0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView5" android:layout_weight="1" android:text="protein" android:layout_gravity="center_vertical|right" android:gravity="right" android:layout_marginRight="5dip" android:textColor="#FFFFFF"></TextView>
            <EditText android:layout_column="1" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="5dip" android:hint="protein" android:gravity="right" android:id="@+id/proteinEditText" android:inputType="numberDecimal" android:imeOptions="actionDone"></EditText>
        </TableRow>

        <TableRow android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/buttonRow" android:layout_margin="8dip">
            <ImageButton android:layout_column="0" android:background="@null" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/calcbuttonbluesquare" android:id="@+id/calcButton"></ImageButton>
            <ImageButton android:layout_column="1" android:background="@null" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clearbuttonbluesquare" android:id="@+id/clearButton"></ImageButton>
        </TableRow>

        <TableRow android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/totalRow">
            <TextView android:layout_column="0" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_gravity="center_vertical|right" android:gravity="right" android:text="TOTAL" android:layout_marginRight="5dip" android:textColor="#FFFFFF"></TextView>
            <TextView android:layout_column="1" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="5dip" android:background="@null" android:gravity="left|right" android:textColor="#FFFFFF" android:clickable="false" android:inputType="none|numberDecimal" android:id="@+id/totalTextView"></TextView>
        </TableRow>

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