Android-针对不同的屏幕尺寸调整图像

标签 android image size screen imageview

我目前有一个带有图像的 imageview。它在我的 2.7"测试屏幕上看起来很完美,但是,当我在我的 4.3"屏幕上测试它时,图像不在应有的位置。我将高度设置为 dp,我的图像文件位于 hdpi、mdpi 和 Ldpi 文件夹中。难道我做错了什么?或者更确切地说,是否有某种方法可以锁定图像的位置,以便它在所有手机尺寸中以相同的方式显示? 谢谢。

没有适应各种屏幕尺寸的imageview是第一个imageview (id = sdrbg) 这是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">
    <ImageView android:layout_width="wrap_content"
        android:layout_alignParentTop="true" android:id="@+id/sdrbg"
        android:background="@drawable/sdrmaingraphic" android:layout_height="289dp"></ImageView>

    <ImageView android:id="@+id/canvasBOM"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="false" android:layout_width="fill_parent"
        android:background="@drawable/canvas" android:layout_height="100dp">
    </ImageView>
    <Button android:layout_alignParentBottom="true"
        android:id="@+id/playpausebuttonBOM" android:background="@drawable/main_pause_button"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:layout_marginLeft="10dp"></Button>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/nextbuttonBOM"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true" android:background="@drawable/next_song_button"
        android:layout_marginRight="10dp"></Button>
    <TextView android:id="@+id/textView1" android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:text="Best of May 2011"
        android:textSize="20dp" android:textStyle="bold"
        android:layout_centerHorizontal="true" android:layout_centerVertical="false"></TextView>
</RelativeLayout>

最佳答案

使用 wrap_content 和 RelativeLayout 特性来指定高度,而不是指定高度。例如:android:layout_alignParentTop="true"android:layout_alignBottom="@id/playPauseButtomBOM"android:layout_marginBottom="xxdp"

关于Android-针对不同的屏幕尺寸调整图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6822881/

相关文章:

Java - 如何查看List接口(interface)中size()方法的定义?

c++ - 堆栈帧的大小总是固定的?

java - 发送文件到android服务器

javascript - 在javascript中设置动画时更改图像颜色

android.os.FileUriExposedException : file. jpg 通过 ClipData.Item.getUri() 暴露在应用程序之外

c# - 在 C# wpf 项目中以编程方式将图像添加到 DataGrid - 如何?

html - Div 未延伸到正文顶部

即使设置了 PATH,也找不到 Android 命令

android - 何时使用 PreferenceFragment 和 PreferenceFragmentCompat?

android - React Native keep 运行失败