【问题标题】:Limiting the width of image to screen width将图像的宽度限制为屏幕宽度
【发布时间】:2012-08-07 15:36:36
【问题描述】:

在我的应用程序中,我使用的是图像。我不希望图像的宽度超过任何密度的任何屏幕尺寸的屏幕宽度。如何实现这一点以及我对所有 android 密度只使用一张图像而不是不同分辨率的图像时会出现什么问题?

【问题讨论】:

    标签: android image width screen


    【解决方案1】:

    试试这个,但您需要为每个分辨率调整大小的图像

    hdpi、ldpi、mdpi 和 xdpi 分辨率

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/title_bar"
        android:gravity="center_vertical" >
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@string/desc"
            android:src="@drawable/YourPicSource" />
    
    </RelativeLayout>
    

    【讨论】:

    • 有什么办法可以避免这种情况吗? “wrap_content”实现了什么?
    • wrap_content 被您的真实图像宽度替换,如果您想在所有屏幕上使用 match_parent 或 fill_parent 更改 wrap_content 我希望对您有所帮助
    猜你喜欢
    • 2012-07-16
    • 2014-03-30
    • 1970-01-01
    • 2022-12-05
    • 2012-02-27
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    • 2015-07-16
    相关资源
    最近更新 更多