【问题标题】:SVG Files goes over the screen in tablelayout and resize the SVG-FilesSVG 文件在 tablelayout 中遍历屏幕并调整 SVG 文件的大小
【发布时间】:2020-04-19 03:41:03
【问题描述】:

我想创建一个小游戏,您可以在其中将您的军队派往其他基地,由谁来接管它。
我使用表格布局来显示关卡的不同部分。
我的图片是 svg 文件,但似乎不适应屏幕尺寸:

我的第一级需要 5 列和 5 行。地图应该是一个简单的正方形,每个角应该是一个底(圆)。小矩形应该是“街道”或基地之间的连接,将由剧团使用。 它应该是这样的:

我的问题: 如何使列、行和 svg 文件适合屏幕大小?
因为我认为可以调整 svg 图像的大小而不会失去其质量,而 android studio 会自动完成,但我不知道如何调整它的大小。
我在第二行也有一个问题:你可以看到两条垂直的街道彼此相邻,但我想把第二条街道放在底部的底部,它在右上角。

这里是xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">

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

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <LinearLayout

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

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/base" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/street_h" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/street_h" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/street_h" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/base" />

            </LinearLayout>
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="fill_parent"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/street_v" />

                <!-- An empty ImageView as a placeholder? -->

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="end"
                    android:src="@drawable/street_v" />
            </LinearLayout>

        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </TableLayout>
</LinearLayout>

我尝试过的:
1.对于第二行使用LinearLayout(水平)将2个图像放在左边和上 正确的。
2. 添加没有线性布局的图像。
3. 玩弄android:layout_widthandroid:layout_height

但是它们都不起作用,我在网络上找不到解决方案:(

我是否为我的想法使用了错误的布局,或者我错过了 TableLayout 的一个重要选项?

更新

我终于可以压缩所有 SVG 文件以适应:

我以编程方式完成所有操作,以便更轻松地创建新关卡,我使用了这部分代码:

// parameters for every row
TableRow.LayoutParams rowParameter = new TableRow.LayoutParams();
rowParameter.height = TableRow.LayoutParams.WRAP_CONTENT;
rowParameter.width = TableRow.LayoutParams.WRAP_CONTENT;
rowParameter.weight = 1000;


// parameters for every image
TableRow.LayoutParams imageParameter = new TableRow.LayoutParams();
imageParameter.height = TableLayout.LayoutParams.WRAP_CONTENT;
imageParameter.width = TableLayout.LayoutParams.WRAP_CONTENT;
imageParameter.weight = 1000;

如您所见,图像太小。我想让它们彼此靠近。我怎样才能做到这一点?

【问题讨论】:

    标签: android android-studio svg tablelayout


    【解决方案1】:

    我明白了!我需要做的只是使用更大的 svg-images 和 Image.setAdjustViewBounds(true); 方法 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-02
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2011-10-27
      • 2012-08-03
      • 1970-01-01
      • 2022-10-15
      相关资源
      最近更新 更多