【问题标题】:How to alter image size in android?如何在android中更改图像大小?
【发布时间】:2019-12-05 17:59:38
【问题描述】:

[在此处输入图片描述][1]我正在尝试使用 android studio 制作纸牌游戏。我已经下载了卡片的图像,并且我希望卡片的大小与设备的屏幕大小相关。我试过使用layout_weight,但还是不行。 这是图像: [1]:https://i.stack.imgur.com/snMNs.png

代码如下: https://i.stack.imgur.com/APhZO.png (抱歉,即使在每行后放置 4 个空格,我也无法弄清楚在 stackoverflow 上制作图像代码的方法,它仍然会给我错误。对此的任何建议也会有所帮助)

【问题讨论】:

  • 代码在哪里?

标签: android xml imageview


【解决方案1】:

解决方案: 1、从RelativeLayout中去掉两个LinearLayout。然后将 imageView 添加为 RelativeLayout 的子项。然后,设置ImageView的属性android:layout_width="wrap_content" android:layout_height="wrap_content"。然后,您的图像将与屏幕尺寸相关。

建议:阅读Developer Docs 了解Layouts 和所有内容。 我希望它有所帮助。如果您对我的回答有任何不明白的地方,请告诉我。

代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/american_style_pool_table_diagram"
    tools:context=".MainActivity"
    android:layout_weight="5">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="401dp"
        android:layout_marginTop="92dp"
        android:contentDescription="image"
        android:scrollbarSize="4dp"
        app:srcCompat="@drawable/acecardpngcardsacespades600" />
</RelativeLayout>

给定代码的预览:

  1. 当您想添加一些代码时,只需复制代码并粘贴到您的详细信息下方,然后仅选择代码部分,然后按“代码示例”按钮(从左到右的第 5 个按钮右)从上面。查看这些:

选择代码:

然后按下这个按钮:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-31
    • 2021-12-16
    • 2021-12-19
    • 1970-01-01
    • 2012-12-06
    • 2015-01-26
    • 1970-01-01
    相关资源
    最近更新 更多