Android TableLayout宽度与RelativeLayout宽度不匹配
我是一名android初学者,有相当多的Java背景,主要是在大型机上。(是的,它在大型机上运行)。我编写了一个跟踪日常活动的应用程序,在默认的RealativeLayout之后,我通过XML添加了一个TableLayout。在onWindowFocusChanged中,我还尝试设置表格布局的宽度。当我测量这两者时,相对长度是1024,屏幕大小,但TableLayout是960。下面是XML和代码片段。任何帮助都将不胜感激,因为我已经做了许多搜索和大量的文档,但仍然无法得到匹配Android TableLayout宽度与RelativeLayout宽度不匹配,android,android-layout,width,tablelayout,Android,Android Layout,Width,Tablelayout,我是一名android初学者,有相当多的Java背景,主要是在大型机上。(是的,它在大型机上运行)。我编写了一个跟踪日常活动的应用程序,在默认的RealativeLayout之后,我通过XML添加了一个TableLayout。在onWindowFocusChanged中,我还尝试设置表格布局的宽度。当我测量这两者时,相对长度是1024,屏幕大小,但TableLayout是960。下面是XML和代码片段。任何帮助都将不胜感激,因为我已经做了许多搜索和大量的文档,但仍然无法得到匹配 <
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/WeekTbar"
android:stretchColumns="*"
android:shrinkColumns="*"
android:layout_alignParentLeft="true"
android:id="@+id/table"
android:background="#d4fbff">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0ff2D2Bf"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_column="0"
android:background="#2d2bff"
android:textColor="#ffffff"
android:text=" " />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:layout_column="1"
android:text="Sun"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText3"
android:layout_column="2"
android:text="Mon"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText4"
android:layout_column="3"
android:text="Tue"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText6"
android:layout_column="4"
android:text="Wed"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText5"
android:layout_column="5"
android:text="Thu"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText8"
android:layout_column="6"
android:text="Fri"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText9"
android:layout_column="7"
android:text="Sat"
android:textColor="#ffffff"
android:background="#2d2bff" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0ff2D2Bf"
android:focusableInTouchMode="true">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText10"
android:layout_column="0"
android:text="Steps"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/SunSteps"
android:layout_column="1"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/MonSteps"
android:layout_column="2"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TueSteps"
android:layout_column="3"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/WedSteps"
android:layout_column="4"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ThuSteps"
android:layout_column="5"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/FriSteps"
android:layout_column="6"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/SatSteps"
android:layout_column="7"
android:background="#2d2bff" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0ff2D2Bf">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText11"
android:layout_column="0"
android:text=Cals"
android:textColor="#ffffff"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/SunCals"
android:layout_column="1"
android:focusableInTouchMode="true"
android:background="#2d2bff"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/MonCals"
android:layout_column="2"
android:textColor="#ffffff"
android:focusableInTouchMode="true"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TueCals"
android:layout_column="3"
android:background="#2d2bff"
android:focusableInTouchMode="true"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/WedCals"
android:layout_column="4"
android:textColor="#ffffff"
android:focusableInTouchMode="true"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ThuCals"
android:layout_column="5"
android:background="#2d2bff"
android:focusableInTouchMode="true"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/FriCals"
android:layout_column="6"
android:textColor="#ffffff"
android:focusableInTouchMode="true"
android:background="#2d2bff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText7"
android:layout_column="7"
android:background="#2d2bff"
android:focusableInTouchMode="true"
android:textColor="#ffffff" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0ff2D2Bf">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText12"
android:layout_column="0"
android:text="Wgt"
android:background="#2d2bff"
android:textColor="#ffffff" />
</TableRow>
</TableLayout>
如果您只希望表布局宽度与RelativeLayoutWidth匹配,则不需要支持多个xml元素。 当您在
RelativeLayout
中支持android:padding
或TableLayout
中支持android:layout\u margin
时,可能会导致您的问题。
检查下面的简单代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="10dp" // remove it
android:layout_height="match_parent" >
...
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:layout_margin="10dp" // remove it
>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
.... >
</TableRow>
....
</TableLayout>
</RelativeLayout>
...
....
请参阅中有关android布局边距和填充的更多信息
如果您只希望表格布局宽度与相对长度宽度匹配,则无需支持多个xml元素,希望获得此帮助。 当您在
RelativeLayout
中支持android:padding
或TableLayout
中支持android:layout\u margin
时,可能会导致您的问题。
检查下面的简单代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="10dp" // remove it
android:layout_height="match_parent" >
...
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:layout_margin="10dp" // remove it
>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
.... >
</TableRow>
....
</TableLayout>
</RelativeLayout>
...
....
请参阅中有关android布局边距和填充的更多信息
希望获得此帮助请显示您的RelativeLayout添加RelativeLayout xml的xml代码。您已在RelativeLayout中添加了android:paddingLeft=“@dimen/activity\u horizontal\u margin”。这可能会占用表布局中的一些空间。在我将所有填充更改为0dp后,请尝试将所有类型的填充设置为0相同的结果。请显示您的RelativeLayoutAdding RelativeLayout xml的xml代码。您已在RelativeLayout中添加了android:paddingLeft=“@dimen/activity\u horizontal\u margin”。这可能会占用表布局中的一些空间。在我将所有填充更改为0dp后,尝试将所有类型的填充设置为0相同的结果。