码迷,mamicode.com
首页 > 其他好文 > 详细

tablelayout高度问题

时间:2014-10-22 00:32:12      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:android   blog   http   ar   sp   div   2014   on   问题   

============问题描述============


我想让tablelayout里面的所有组件的高度加起来刚好占满屏幕,应该怎么设置?
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
android:textSize="50sp" >

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <EditText
            android:id="@+id/result"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@drawable/result_bg"
            android:editable="false"
            android:layout_span="4" 
            android:gravity="right|center_vertical"
            android:layout_margin="10dp"
            android:layout_weight="1" >
<requestFocus />
        </EditText>

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/delete"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="del" 
            android:layout_weight="1" />

        <Button
            android:id="@+id/equal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="="
            android:layout_weight="1" />

    </TableRow>
  
    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/number1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1"
            android:layout_weight="1" />

        <Button
            android:id="@+id/number2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="2"
            android:layout_weight="1" />

        <Button
            android:id="@+id/number3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="3"
            android:layout_weight="1" />

        <Button
            android:id="@+id/add"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="+"
            android:layout_weight="1" />

    </TableRow>
    
    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/number4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="4"
            android:layout_weight="1" />

        <Button
            android:id="@+id/number5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="5"
            android:layout_weight="1" />

        <Button
            android:id="@+id/number6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="6"
            android:layout_weight="1" />

        <Button
            android:id="@+id/minus"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="-"
            android:layout_weight="1" />

    </TableRow>
    
    <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/number7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="7"
            android:layout_weight="1" />

        <Button
            android:id="@+id/number8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="8"
            android:layout_weight="1" />

        <Button
            android:id="@+id/number9"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="9"
            android:layout_weight="1" />

        <Button
            android:id="@+id/multiply"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="*"
            android:layout_weight="1" />

    </TableRow>
    
    <TableRow
        android:id="@+id/tableRow6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/ac"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="ac"
            android:layout_weight="1" />
        <Button
            android:id="@+id/number0"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:layout_weight="1" />

        <Button
            android:id="@+id/dot"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="." 
            android:layout_weight="1" />

        <Button
            android:id="@+id/divide"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="/"
            android:layout_weight="1" />

    </TableRow>

</TableLayout>
目前效果是这样
bubuko.com,布布扣

============解决方案1============


修改TableRow的layout_height,增加layout_weight:

    <TableRow

        android:layout_width="match_parent"

        android:layout_height="0dp"

        android:layout_weight="1">



根据需要修改TableRow中的控件的layout_height:

android:layout_height="match_parent"



修改后的xml:

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

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

	android:textSize="50sp" >



    <TableRow

        android:layout_width="match_parent"

        android:layout_height="0dp"

        android:layout_weight="1" >

        <EditText

            android:id="@+id/result"

            android:layout_width="match_parent"

            android:layout_height="60dp"

            android:background="@drawable/result_bg"

            android:editable="false"

            android:layout_span="4" 

            android:gravity="right|center_vertical"

            android:layout_margin="10dp"

            android:layout_weight="1" >

			<requestFocus />

        </EditText>



    </TableRow>



    <TableRow

        android:id="@+id/tableRow2"

        android:layout_width="match_parent"

        android:layout_height="0dp"

        android:layout_weight="1" >



        <Button

            android:id="@+id/delete"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:layout_span="2"

            android:text="del" 

            android:layout_weight="1" />



        <Button

            android:id="@+id/equal"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:layout_span="2"

            android:text="="

            android:layout_weight="1" />



    </TableRow>

  

    <TableRow

        android:id="@+id/tableRow3"

        android:layout_width="match_parent"

        android:layout_height="0dp"

        android:layout_weight="1" >



        <Button

            android:id="@+id/number1"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="1"

            android:layout_weight="1" />



        <Button

            android:id="@+id/number2"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="2"

            android:layout_weight="1" />



        <Button

            android:id="@+id/number3"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="3"

            android:layout_weight="1" />



        <Button

            android:id="@+id/add"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="+"

            android:layout_weight="1" />



    </TableRow>

    

    <TableRow

        android:id="@+id/tableRow4"

        android:layout_width="match_parent"

        android:layout_height="0dp"

        android:layout_weight="1" >



        <Button

            android:id="@+id/number4"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="4"

            android:layout_weight="1" />



        <Button

            android:id="@+id/number5"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="5"

            android:layout_weight="1" />



        <Button

            android:id="@+id/number6"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="6"

            android:layout_weight="1" />



        <Button

            android:id="@+id/minus"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="-"

            android:layout_weight="1" />



    </TableRow>

    

    <TableRow

        android:id="@+id/tableRow5"

        android:layout_width="match_parent"

        android:layout_height="0dp"

        android:layout_weight="1" >



        <Button

            android:id="@+id/number7"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="7"

            android:layout_weight="1" />



        <Button

            android:id="@+id/number8"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="8"

            android:layout_weight="1" />



        <Button

            android:id="@+id/number9"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="9"

            android:layout_weight="1" />



        <Button

            android:id="@+id/multiply"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="*"

            android:layout_weight="1" />



    </TableRow>

    

    <TableRow

        android:id="@+id/tableRow6"

        android:layout_width="match_parent"

        android:layout_height="0dp"

        android:layout_weight="1" >



        <Button

            android:id="@+id/ac"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="ac"

            android:layout_weight="1" />

        <Button

            android:id="@+id/number0"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="0"

            android:layout_weight="1" />



        <Button

            android:id="@+id/dot"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="." 

            android:layout_weight="1" />



        <Button

            android:id="@+id/divide"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:text="/"

            android:layout_weight="1" />



    </TableRow>



</TableLayout>

tablelayout高度问题

标签:android   blog   http   ar   sp   div   2014   on   问题   

原文地址:http://www.cnblogs.com/liangxieliang56/p/4041901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!