如何通过设备保持图像比例?

时间:2015-04-08 16:01:35

标签: android android-studio

我正在编写一个简单的纸牌游戏,但我的模拟器和我自己的手机之间的图像并不相同。 我尝试了android:src="@drawable/card_a"android:background="@drawable/card_a",但它不起作用。这里有一些截图来解释:

  - 使用android:src,它显示非常小的图像。

我希望在我的手机中看到来自我的模拟器的相同显示。

3 个答案:

答案 0 :(得分:2)

问题似乎不是图像背景,而是包含此图像的视图。可能你应该在所有这些中使用android:weight="1",并将所有这些ImageView放在一个水平方向的LinearLayout中。

答案 1 :(得分:0)

在版面文件中添加android:scaleType="FitInCenter"

答案 2 :(得分:0)

您可以像这样使用LinearLayout权重:

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
android:weight_sum="5" >

            <ImageView
                android:id="@+id/card1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/card2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/card3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/card4"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/card5"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

        </LinearLayout>

这样你总能得到5个相同宽度的视图。