2011-04-23 65 views
10

我想知道如何增加表格行的高度,使其在较大的屏幕尺寸中看起来成比例。目前,所有文本浏览和编辑文本(放置在表格行中)都出现在屏幕的左侧,而不是占据整个屏幕(仅适用于更大的屏幕尺寸)。 这里是我一起工作的XML:如何根据屏幕增加表格行的高度?

<ScrollView android:id="@+id/ScrollView01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android">  

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 

    android:layout_height="fill_parent" android:background="@color/black_background"> 

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    > 
    <TableRow android:id="@+id/TableRow01" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 


    <TextView android:id="@+id/name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:textColor="@color/white" 
      android:visibility="visible" 
      android:text="@string/Name" 
      android:layout_weight="0.2" 
      android:layout_marginLeft="20dp" 
      android:layout_marginTop="22dp"/> 

<EditText android:id="@+id/myName" 
      android:layout_width="120dip" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:visibility="visible" 
      android:layout_weight="0.3" 
      android:inputType="number" 
      android:textColor="@color/black_background" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp"/> 

<TextView android:id="@+id/error1" 
       android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" 
      android:textColor="@color/red" 
      android:visibility="visible" 
      android:layout_weight="0.5"/> 

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


    <TextView android:id="@+id/address" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:visibility="visible" 
      android:textColor="@color/white" 
      android:text="@string/address" 
      android:layout_weight="0.2" 
      android:layout_marginLeft="20dp" android:layout_marginTop="22dp"/> 

<EditText android:id="@+id/address" 
      android:layout_width="120dip" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:visibility="visible" 
      android:inputType="number" 
      android:textColor="@color/black_background" 
      android:layout_weight="0.8" 
      android:layout_marginLeft="10dp" android:layout_marginTop="10dp"/> 

    </TableRow> 
</TableLayout>   

    </LinearLayout> 
</ScrollView> 

回答

6

请通过此链接,我认为这将帮助你。 http://developerlife.com/tutorials/?p=307

请注意,TableLayout的子女不能指定他们的宽度 - 这总是FILL_PARENT。但是,高度可以由儿童定义,默认为WRAP_CONTENT。如果孩子是TableRow,那么身高总是WRAP_CONTENT

所以如果你使用TableLayoutTableRows你不能真的不能设置宽度/高度(width=FILL_PARENTheight=WRAP_CONTENT)。

顺便说一句,TableRow只是LinearLayout的子类。你可以做的是指定列的行为来收缩和/或拉伸或不拉伸。您也可以通过在TableLayout上调用setColumnCollapsed并将其传递给列索引来隐藏列。所有列索引都从0开始,并且可以有空列。

4

您可以使用android:layout_weight。在下面的例子中的代码,左键是两倍大,右边的按钮:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" 
      android:text="hai" /> 
    <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="2" 
      android:text="longer sentence" /> 
</LinearLayout> 
21

使用

android:minHeight="60px" 

TableRow标签

<TableRow android:id="@+id/task1" android:layout_width="fill_parent" 
      android:minHeight="60px" android:layout_height="wrap_content"> 
+1

'minHeight'作品..谢谢! – 2015-08-05 11:06:29

0

您可以申请android:layout_weight为tablerow并为所有表行赋予相等的值。表行将分布在线性布局的剩余空间中。

确保,你已经设置如下属性TableLayout

android:layout_width="match_parent" 
android:layout_height="match_parent" 
1

您可以设置每个TableRow为1的android:layout_weight然后改变的TableLayout高度,只要你喜欢。这对我来说可以!

android:layout_weight="1" 
2

这个属性添加到您的所有TableRow S:

android:layout_height = "0dp" 
android:layout_weight = "1" 

这绵延所有TableRow s到占全家长的高度。

+0

该解决方案适用于我。 – 2016-12-20 13:39:37

相关问题