【问题标题】:Table layout not fitting screen表格布局不适合屏幕
【发布时间】:2013-04-18 00:23:22
【问题描述】:

我有一个动态创建表格的活动。活动已创建并且运行良好。

这是xml文件的源代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#142c57"
    tools:context=".TableActivity" >

    <TextView
        android:id="@+id/heading_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="@string/followup_list" 
        android:textColor="#FFFFFF"
        android:textSize="15sp"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/heading_textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp" 
        android:padding="3dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" 
            android:background="@drawable/inner_box">

            <ScrollView
                android:id="@+id/scrollView1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true" >

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >

                    <HorizontalScrollView
                        android:id="@+id/horizontalScrollView1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true" >

                        <TableLayout
                            android:id="@+id/follow_up_table"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent" 
                            android:stretchColumns="0">


                        </TableLayout>

                    </HorizontalScrollView>

                </RelativeLayout>

            </ScrollView>

        </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>

xml文件的输出:

我想让桌子填满整个盒子,桌子右侧的空间不是必需的,看起来很尴尬。要做到这一点要做什么?

【问题讨论】:

    标签: java android background tablelayout


    【解决方案1】:

    更好地拉伸和收缩所有列以适应您的屏幕:

    <TableLayout
     android:id="@+id/follow_up_table"
     android:layout_width="match_parent"
     android:layout_height="match_parent" 
     android:stretchColumns="*"
     android:shrinkColumns="*">
    
    </TableLayout>
    

    【讨论】:

      【解决方案2】:

      你的表格布局宽度包裹了它的内容,应该是match_parent

      <TableLayout
       android:id="@+id/follow_up_table"
       android:layout_width="match_parent"
       android:layout_height="match_parent" 
       android:stretchColumns="0">
      
      
      </TableLayout>
      

      【讨论】:

        【解决方案3】:

        改变如下:

        <TableLayout
            android:id="@+id/follow_up_table"
            android:layout_width="fill_parent"
            android:layout_height="match_parent" 
            android:stretchColumns="0">
        </TableLayout>
        

        变化是:

        android:layout_width="**fill_parent**"
        

        【讨论】:

          【解决方案4】:

          使用 Horizo​​ntalScrollView 的目的是什么?只需将其删除并将 TableLayout 的 android:layout_width 设置为 match_parent。

          【讨论】:

            【解决方案5】:

            需要像这样编辑布局

            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="#142c57"
                tools:context=".TableActivity" >
            
                <TextView
                    android:id="@+id/heading_textView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="10dp"
                    android:text="@string/followup_list" 
                    android:textColor="#FFFFFF"
                    android:textSize="15sp"/>
            
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/heading_textView"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="10dp" 
                    android:padding="3dp">
            
                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true" 
                        android:background="@drawable/inner_box">
            
                        <ScrollView
                            android:id="@+id/scrollView1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentTop="true" >
            
                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content" >
            
                                <TableLayout
                                    android:id="@+id/follow_up_table"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_alignParentLeft="true"
                                    android:layout_alignParentTop="true" 
                                    android:stretchColumns="0,1">
            
            
                                </TableLayout>
            
                            </RelativeLayout>
            
                        </ScrollView>
            
                    </RelativeLayout>
            
                </RelativeLayout>
            
            </RelativeLayout>
            

            输出

            【讨论】:

            • 发现差异并不容易,让我发现它... android:stretchColumns="0,1"
            猜你喜欢
            • 1970-01-01
            • 2013-02-05
            • 2021-09-15
            • 2017-07-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-02-07
            相关资源
            最近更新 更多