2015-09-27 87 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