2015-09-27 66 views
0

我是新来的android。我试图在屏幕底部放置5个图标。我创建了不同分辨率的图标,即ldpi,mdpi,hdpi,xhdpi和xxhdpi。我使用下面的布局适合多个屏幕分辨率的布局ImageView元素

<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> 

enter image description here

我加入图标编程到孩子相对布局。但在屏幕较小的设备上,我遇到了图像中提到的问题。 在屏幕为480 * 854的设备中,大小(96 * 96)的hdpi图标正在加载,但正在屏幕之外。根据我的理解,如果我可以使其在适当尺寸的屏幕上工作并提供其他分辨率的图标,则应该自动进行处理。如果我错了,请纠正我。任何人都可以帮我解决这个问题吗?

回答

1

设置每个imageview的宽度和高度,你需要先计算屏幕宽度,然后设置每个ImageView的宽度来筛选宽度/ 5类似如下:

Display display = getWindowManager().getDefaultDisplay(); 
Point size = new Point(); 
display.getSize(size); 
int screenWidth = size.x; 
int iconWidth = (int) screenWidth/5; 

然后设置每个的ImageView到iconWidth的宽度。

1

因为每个设备类型mdpi,hdpi,xhdpi都有很多种不同的屏幕尺寸。
因此,我的建议是:
如果添加图像布局编程您应该计算屏幕的宽度,然后通过屏幕宽度/ 5