【问题标题】:How to increase the height of table row according to screens?如何根据屏幕增加表格行的高度?
【发布时间】:2019-01-22 17:33: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> 

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    使用

    android:minHeight="60px"
    

    TableRow 标签上

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

    【讨论】:

      【解决方案2】:

      请通过这个链接,我想它会帮助你。 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 开始,您可以有空列。

      【讨论】:

        【解决方案3】:

        您可以只使用 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>
        

        【讨论】:

          【解决方案4】:

          将以下属性添加到您的所有TableRows:

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

          它会拉伸你所有的TableRows 以占据整个父级高度。

          【讨论】:

            【解决方案5】:

            您可以将每个TableRowandroid:layout_weight 设置为1。然后根据需要更改TableLayout 的高度。对我来说很好用!

            android:layout_weight="1" 
            

            【讨论】:

              【解决方案6】:

              您可以将android:layout_weight 应用于 TableRow 并为所有表行赋予相同的值。表格行将分布在线性布局的剩余空间中。

              确保您已将以下属性设置为 TableLayout

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

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2017-12-07
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多