【问题标题】:How to set an image view in to different screen sizes如何将图像视图设置为不同的屏幕尺寸
【发布时间】:2015-04-26 18:40:27
【问题描述】:

在我的应用程序中,我使用了图像视图,我选择了宽度和高度作为匹配父级和填充父级,但图像仍然小于我的屏幕尺寸。这段代码有什么问题。我知道这是一个愚蠢的问题,我我是android新手,我想解决这个问题,有人可以提供解决方案吗?

我的 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:id="@+id/imageView" />
<Button
        android:id="@+id/btnAddExpense"
        android:layout_width="wrap_content"
        android:layout_height="45dp"

        android:text="Skip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>

图像视图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"
        android:id="@+id/imageView" />
<Button
        android:id="@+id/btnAddExpense"
        android:layout_width="wrap_content"
        android:layout_height="45dp"

        android:text="Skip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>

【问题讨论】:

  • 你在ImageView中有一张图片?

标签: android android-layout android-imageview android-xml android-imagebutton


【解决方案1】:

默认情况下,ImageView 控件的内容具有一定的大小——通常是图像尺寸的大小。为了解决这个问题,您需要将android:adjustViewBounds="true" 添加到您的ImageViewandroid:scaleType="fitXY"

【讨论】:

  • 我已经添加了,但问题仍然没有解决。还有其他更改吗??
  • 你好,我已经添加了,android:adjustViewBounds="true",并且比例类型= fitXY,但是显示没有变化,问题仍然存在,
  • 您可以使用您的 imageview 参数,使用 guides.codepath.com/android/Working-with-the-ImageView#overview 但我很确定它现在应该已经工作了。也许您需要告诉 imageview 位于按钮上方,但除此之外,您失去了我。
  • 谢谢,我不知道实际的问题是什么,请看我的编辑
猜你喜欢
  • 2015-02-28
  • 2018-12-19
  • 2011-04-21
  • 1970-01-01
  • 1970-01-01
  • 2015-08-28
  • 2015-07-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多