Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Eclipse-在我的表格布局上增加边距_Android_Eclipse_Android Layout_Formatting_Margin - Fatal编程技术网

Android Eclipse-在我的表格布局上增加边距

Android Eclipse-在我的表格布局上增加边距,android,eclipse,android-layout,formatting,margin,Android,Eclipse,Android Layout,Formatting,Margin,我对如何增加我的TableLayout的总宽度以便更靠近屏幕的两侧感到有点困惑 我不确定是在实际的表格布局本身,还是在父级RelativeLayout中进行调整 图片: 有什么想法吗 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pare

我对如何增加我的
TableLayout
的总宽度以便更靠近屏幕的两侧感到有点困惑

我不确定是在实际的
表格布局
本身,还是在父级
RelativeLayout
中进行调整

图片:

有什么想法吗

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.funkycalc.MainActivtiy\" >

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" >

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

        <Button
            android:id="@+id/button1"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="CLR" />

        <Button
            android:id="@+id/button2"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="DEL" />
    </TableRow>

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

        <Button
            android:id="@+id/button5"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1" />

        <Button
            android:id="@+id/button6"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2" />

        <Button
            android:id="@+id/button7"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3" />

        <Button
            android:id="@+id/button8"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="+" />
    </TableRow>

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

        <Button
            android:id="@+id/button9"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="4" />

        <Button
            android:id="@+id/button10"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="5" />

        <Button
            android:id="@+id/button11"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="6" />

        <Button
            android:id="@+id/button12"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="-" />
    </TableRow>

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

        <Button
            android:id="@+id/button13"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="7" />

        <Button
            android:id="@+id/button14"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="8" />

        <Button
            android:id="@+id/button15"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="9" />

        <Button
            android:id="@+id/button16"
            style="?android:attr/buttonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="/" />
    </TableRow>

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

        <Button
            android:id="@+id/button17"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="0" />

        <Button
            android:id="@+id/button18"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="." />

        <Button
            android:id="@+id/button20"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="x" />
    </TableRow>

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

        <Button
            android:id="@+id/button3"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="4"
            android:text="=" />
    </TableRow>

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

</TableLayout>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="40dp"
    android:text="Result"
    android:textSize="55dp" />


您可以在表格布局中使用
匹配父项
,这样它将获取父项的全宽,然后调整左右填充以生成所需的间隔。请记住,您已经在相对布局中定义了一个填充,因此您需要同时使用这两个值

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" >

您将
android:layout\u width=“wrap\u content”
设置为
TableLayout
,使其宽度刚好足以显示所有内容。尝试使用
match\u parent
使其占据整个父级宽度:

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" >
在父级
RelativeLayout
中。如果第一步不适合您的需要,您可以尝试设置较低的
paddingLeft
paddingRight
值。

尝试此编辑

    <RelativeLayout 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"

tools:context="com.example.funkycalc.MainActivtiy\" >

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" >


填充值是问题所在…

嘿,Axis,它开始工作了,但仍然有一个问题…tableLayout周长(蓝色)正是我想要的,但按钮无法填充空间!!什么?您的按钮和行的宽度为wrap_内容。由于TableRow是一个线性布局,您应该能够将按钮宽度设置为0,权重设置为1,
android:layout\u width='0dp',android:layout\u weight='1'
,这样按钮将按比例占用所有可用空间。最后,Tablerow应该使用
match\u parent
Awesome axxis,非常好的建议。它就快到了……不过,我希望我的“0”按钮显示为一个大按钮,就像我在帖子的原始图像中发布的那样。我该怎么做?我认为宽度=0,重量=1是不可能的。。。您可以在这里看到问题:尝试将zero按钮设置为weight=1,将其他两个按钮设置为weight=0。你将不得不玩弄这些价值观。或者使用双线布局,一个带有一个按钮,另一个带有其他两个按钮!!对于0,权重=1;对于其他两个,权重=0.5。现在效果很好。谢谢你的帮助,干杯
    <RelativeLayout 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"

tools:context="com.example.funkycalc.MainActivtiy\" >

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" >