Android - 将TableLayout扩展到屏幕大小

时间:2016-03-25 19:34:41

标签: android xml

我的Android应用包含RelativeLayout,其中包含TableLayout

TableLayout内,3 ImageView行中的每一行都有3 TableLayout秒。 (总共9个)

我遇到的问题是每行中的最后一个ImageView被部分切断了。

这是我当前的xml代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    tools:context=".Main">
    <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:shrinkColumns="true"
            android:id="@+id/TableLayout">
            <TableRow
                android:id="@+id/TableRow1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageView 
                    android:id="@+id/s1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="5dp"/>
                <ImageView 
                    android:id="@+id/s2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="5dp"/>
                <ImageView 
                    android:id="@+id/s3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="5dp"/>
            </TableRow>
    </TableLayout>
</RelativeLayout>

(其余行相同)

我尝试使用fill_parentwrap_content等值,但我还没有取得任何成功。

我想将TableLayout缩放到屏幕大小,以便在所有设备上看起来都不错,而且不会切断任何图像。

这是一个截图: screenshot

提前致谢!

1 个答案:

答案 0 :(得分:0)

您可能希望使用LinearLayout作为父级,并且TableLayout内部使用权重,这样您的行和列将通过均匀划分总空间来均匀分布。

如果您希望图片适合分配的空间,请使用match_parent android:scaleType="fitXY" ImageViews TableLayout内的{{1}}高度和重量。还可以使用其他图像缩放算法,以获得最佳效果(以满足您的需求)尝试使用它,并查看最适合您的内容。

相关问题