【问题标题】:How to fit URL image into the screen on android?如何将 URL 图像放入 android 的屏幕中?
【发布时间】:2017-01-12 19:26:03
【问题描述】:

我从 url 获取图像,但它不适合屏幕,因为它在浏览器上显示...请帮助..我尝试了一切..这个 url "http://i.imgur.com/DvpvklR.png" 这是图片

如果我们在浏览器上运行 url,我们可以在我的设备上看到它略微上升..我希望它在我的设备上看起来很完美

这是我的 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="match_parent"

    >


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

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.7">

            <ImageView
                android:id="@+id/ms1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/main1" />


        </LinearLayout>

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


            <ImageView
                android:id="@+id/ms2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight=".5"

                android:scaleType="fitXY"

                android:src="@drawable/pl2" />

            <ImageView
                android:id="@+id/ms3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight=".5"
                android:scaleType="fitXY"
                android:src="@drawable/l1" />
        </LinearLayout>
    </LinearLayout>


</RelativeLayout>

【问题讨论】:

  • 您希望将图像设置为屏幕的背景图像,并将其他两个图像放在它上面吗?
  • 不,这是第一张图片,下面的图片是第二张和第三张
  • 主屏幕图像没有背景图像
  • 它是 70:30 的比例,第一张图像应占屏幕的 70%,其他图像应占 30%
  • 对于您正确使用权重的比率并在 ImageView 中正确调整图像显示图像,您可以设置 adjustViewBounds="true"

标签: android image


【解决方案1】:

将此添加到您的 Imageview ,

                android:adjustViewBounds="true"
                android:layout_alignParentBottom="true"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"

【讨论】:

  • 我在 url 中拍摄的任何图像都会略微向上
  • 清理您的项目并重试
【解决方案2】:

为此,您可以使用名为 glide 的库

【讨论】:

  • 如何在代码中使用它......因为我已经使用毕加索作为 url 图片
  • 我是 android 新手 ..所以不太了解它...如果你通过编码告诉我,那就是 wud b grt
  • 我在 url 中拍摄的任何图像都会略微向上
【解决方案3】:

看看它是否有效。

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/ms1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:src="@drawable/main1"/>


        </LinearLayout>

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


            <ImageView
                android:id="@+id/ms2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight=".5"
                android:scaleType="fitXY"
                android:src="@drawable/pl2"/>

            <ImageView
                android:id="@+id/ms3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight=".5"
                android:scaleType="fitXY"
                android:src="@drawable/l1"/>
        </LinearLayout>
    </LinearLayout>


</RelativeLayout>

【讨论】:

  • 不只是显示单个图像..但顶部仍然被切割
  • 我在发布后立即编辑了答案。可以再试一次吗?
  • 我在 url 中拍摄的任何图像都会略微向上
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-24
  • 2013-01-03
  • 2012-06-17
  • 1970-01-01
  • 1970-01-01
  • 2011-02-05
相关资源
最近更新 更多