如何强制TableLayout适应整个屏幕?

乔·史密斯

目前,我正在尝试在Android的运行时创建基本的表格布局。我尝试了Wrap_Content,Match_Parent和设置权重的每种组合,但似乎没有任何效果。

本质上我想要这样:

        Title

文字A * ** * ** *文字A1

文字B * ** * ** *文字B1

文字C * ** * ** *文字C1

*指空格(对不起,我无法弄清楚如何格式化)。我希望此操作继续进行,以使其在水平和垂直方向上都充满屏幕。目前,我可以使其水平适应屏幕,但底部却留有很大的空白。

我的XML是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/blackboard"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="Classes"
    android:textColor="@color/white"
    android:textSize="25sp"
    android:textStyle="bold"
    android:typeface="serif" />
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:scrollbars="none"
    android:layout_weight="1">
    <TableLayout
        android:id="@+id/displayTableForClasses"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:shrinkColumns="*"
        android:stretchColumns="*" >

</TableLayout>
</ScrollView>

我本质上需要的是一种缩放字体的方式,以使其垂直填充整个屏幕而不会环绕。最好的情况是使字体大小尽可能大而不引起环绕,然后增加不同TextViews之间的边距,以使其充满整个屏幕。

今井美里

您需要先在父级布局中更改宽度和高度。例如,如果您使用RelativeLayout,则需要更改布局属性,例如:

android:layout_width="fill_parent"
android:layout_height="fill_parent"

然后在您的TableLayout中,您可以使用

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

使用这个:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView1" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView4" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView2" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView3" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使 tableLayout 元素适合屏幕

有人知道如何调整背景颜色以适应整个屏幕宽度吗?

如何使屏幕适应Android中的小屏幕?

如何闪烁整个屏幕?

如何获得Android TableLayout填充屏幕?

如何使UIImage适应整个UINavigationBar视图的大小

如何适应Android中的标签宽度屏幕

如何使用 AutoLayout 在屏幕中适应 UITableView

如何使动画适应不同的屏幕尺寸?迅速

如何使Bootstrap Carousel适应屏幕的100%?

如何适应任何弯曲的屏幕?- 颤振

如何拍摄整个屏幕的屏幕截图

如何使div覆盖整个屏幕

如何使内容填满整个屏幕?

初始比例= 1.0 +宽度=设备宽度无法适应任何移动设备的整个屏幕

拉伸 <img> 以适应整个屏幕而不保持纵横比和滚动条

TableLayout超出屏幕

如何使 RaisedButton 在颤动中自动适应屏幕宽度

在PowerShell中,如何调整表格以适应屏幕分辨率?

如何导出为HTML时报告大小适应屏幕大小

如何使zk boderlayout适应任何分辨率的屏幕

如何防止ImageView调整大小以适应屏幕大小?

laravel bootstrap-如何对齐侧边栏以适应不同的屏幕?

Android-如何使每个TableRow适应屏幕高度

flutter:如何使用相同的程序适应所有屏幕尺寸?

如何使我的Gideros游戏适应所有屏幕尺寸?

带表的 Bootstrap Laravel 以及如何适应屏幕

无论屏幕大小如何,如何使图像完全适合整个屏幕?

如何使用createJ创建自适应画布以适应不同移动设备的屏幕?