【发布时间】:2019-11-21 00:38:44
【问题描述】:
我已将不同尺寸的图片放入 mdpi、hdpi、xhdpi 等。但使用该图像的 My ImageButtons 在每台设备上的大小似乎都相同。
上次我这样做时,它只将图像放在文件夹中。我不记得我到底做了什么。
我想在不同的屏幕上显示不同大小的图像。 我有
- 5.7寸手机
- 5.0寸手机
- 7.0英寸平板电脑
我的应用在所有这些按钮中显示相同大小的图像按钮。
<?xml version="1.0" encoding="utf-8"?>
<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="@color/bg"
tools:context="test.music.MainActivity">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dip">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/nowplayingname_txtv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1"
android:scrollbars="horizontal"
android:text="Ek Mulaqat-www.songsfarm.ifo"
android:textColor="@color/title"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/npduration_txtv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1"
android:text="05:12"
android:textColor="@android:color/darker_gray" />
</LinearLayout>
<ImageButton
android:id="@+id/settings_imgbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/bg"
android:paddingLeft="20dip"
android:paddingRight="20dip"
app:srcCompat="@mipmap/menu" />
</LinearLayout>
<ListView
android:id="@+id/songs_listv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_weight="1"
android:longClickable="true"
android:layout_below="@+id/linearLayout3"
android:layout_above="@+id/song_seekbar" />
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal"
android:paddingBottom="16dp">
<ImageButton
android:id="@+id/prev_imgbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/bg"
app:srcCompat="@mipmap/prev" />
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:id="@+id/pp_imgbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/bg"
app:srcCompat="@mipmap/play" />
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:id="@+id/next_imgbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="@color/bg"
app:srcCompat="@mipmap/next" />
</LinearLayout>
<SeekBar
android:id="@+id/song_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingBottom="16dip"
android:paddingTop="16dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/linearLayout3">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#D3D3D3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignTop="@+id/song_seekbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#D3D3D3" />
</LinearLayout>
</RelativeLayout>
注意: 已经很长时间了,但事实证明将文件放在正确的文件夹中是可行的。文件的名称应该完全相同。您可以通过将图像与文件夹中已存在的图像进行比较来验证图像的大小。
【问题讨论】:
-
你想得到什么效果?以英寸为单位的相同物理尺寸?使用相同百分比的屏幕?还有什么?
-
我想在不同的屏幕上显示不同尺寸的图像。我有一部 5.7 英寸手机、一部 5.0 英寸手机和一部 7 英寸平板电脑。我的应用在所有这些按钮中显示相同大小的图像按钮
-
不同的尺寸——不同的物理尺寸,还是逻辑尺寸?例如,您是否希望它们都高 1 英寸,而不管电话如何?或者你想让它们都占据一半的高度?您不太可能只想要随机的不同尺寸。您需要以更详细的方式描述您想要的最终结果,答案因具体内容而异。
-
正确地说,不是您放入这些文件夹中大小不同的图像,而是更高的分辨率,通常更大只是为了显示更多像素
-
例如,如果我有一个 1 英寸的屏幕,它显示的图片大小为 0.2 英寸。当屏幕尺寸更改为 10 英寸时,它应该显示 2 英寸的图像。
标签: android imageview android-resources