在具有多种屏幕分辨率的布局上调整 ImageView 元素
Fitting ImageView elements on layout with multiple screen resolutions
我是 android 的新手。我试图在屏幕底部放置 5 个图标。我创建了不同分辨率的图标,即 ldpi、mdpi、hdpi、xhdpi 和 xxhdpi。我正在使用以下布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/gameRootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.xx.drops.MainActivity" >
<RelativeLayout
android:id="@+id/bucketLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="0dp"
android:layout_marginBottom="25dp" >
</RelativeLayout>
</RelativeLayout>
我正在以编程方式将图标添加到子相关布局中。但是在屏幕较小的设备上,我 运行 遇到了问题,如图所示。
在屏幕为 480*854 的设备中,正在加载大小为 (96*96) 的 hdpi 图标,但超出了屏幕范围。根据我的理解,如果我能让它在适当尺寸的屏幕上工作并提供其他分辨率的图标,它应该会被自动处理。如果我错了,请纠正我。谁能帮我解决这个问题?
因为,每种设备类型 mdpi、hdpi、xhdpi 都有许多不同的屏幕尺寸。
因此,我的建议是:
如果您以编程方式将图像添加到布局,您应该计算屏幕的宽度,然后通过 screenwidth / 5
设置每个图像视图的宽度和高度
需要先计算屏幕宽度,然后将每个ImageView的宽度设置为屏幕宽度/5,如下所示:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int screenWidth = size.x;
int iconWidth = (int) screenWidth / 5;
然后设置每个ImageView的宽度为iconWidth。
我是 android 的新手。我试图在屏幕底部放置 5 个图标。我创建了不同分辨率的图标,即 ldpi、mdpi、hdpi、xhdpi 和 xxhdpi。我正在使用以下布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/gameRootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.xx.drops.MainActivity" >
<RelativeLayout
android:id="@+id/bucketLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="0dp"
android:layout_marginBottom="25dp" >
</RelativeLayout>
</RelativeLayout>
我正在以编程方式将图标添加到子相关布局中。但是在屏幕较小的设备上,我 运行 遇到了问题,如图所示。 在屏幕为 480*854 的设备中,正在加载大小为 (96*96) 的 hdpi 图标,但超出了屏幕范围。根据我的理解,如果我能让它在适当尺寸的屏幕上工作并提供其他分辨率的图标,它应该会被自动处理。如果我错了,请纠正我。谁能帮我解决这个问题?
因为,每种设备类型 mdpi、hdpi、xhdpi 都有许多不同的屏幕尺寸。
因此,我的建议是:
如果您以编程方式将图像添加到布局,您应该计算屏幕的宽度,然后通过 screenwidth / 5
需要先计算屏幕宽度,然后将每个ImageView的宽度设置为屏幕宽度/5,如下所示:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int screenWidth = size.x;
int iconWidth = (int) screenWidth / 5;
然后设置每个ImageView的宽度为iconWidth。