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

前端 未结 3 1132
栀梦
栀梦 2021-01-26 04:26

I am new to Android Development and I am having trouble with my XML Layout... when I inly have rows with text and edittext the layout stays ok, but once I put the row with the b

相关标签:
3条回答
  • 2021-01-26 04:54

    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>
    
    0 讨论(0)
  • 2021-01-26 04:55

    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.

    0 讨论(0)
  • 2021-01-26 05:08

    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.

    0 讨论(0)
提交回复
热议问题