2015-04-24 26 views
1

我想對齊一個圖像視圖,該圖像視圖對於所有安卓屏幕期望的Android選項卡屏幕都顯示相同。當應用程序在仿真器或實時設備上運行時,imageview會發現imageview的不同對齊方式。我如何正確對齊它們?如何對齊所有Android屏幕的圖像視圖

這裏是我的activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
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=".MainActivity" 
android:background="#fff" > 

<ImageView 
    android:id="@+id/forts" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginRight="150dp" 
    android:src="@drawable/forts" /> 

<ImageView 
    android:id="@+id/portal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/forts" 
    android:layout_below="@+id/forts" 
    android:src="@drawable/portal" /> 

<ImageView 
    android:id="@+id/emergency" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/forts" 
    android:layout_toRightOf="@+id/portal" 
    android:src="@drawable/emergency" /> 

<ImageView 
    android:id="@+id/aboutus" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/portal" 
    android:layout_toLeftOf="@+id/emergency" 
    android:src="@drawable/aboutus" /> 

<ImageView 
    android:id="@+id/maps" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/emergency" 
    android:layout_alignLeft="@+id/emergency" 
    android:src="@drawable/maps" /> 

<ImageView 
    android:id="@+id/mailus" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/emergency" 
    android:layout_alignTop="@+id/aboutus" 
    android:src="@drawable/mailus" /> 

</RelativeLayout> 
+1

您可以使用繪製文件夾和捫文件夾放置不同勢圖像MDPI,華電國際,LDPI ,xhdpi等 –

回答

2

可以已設置不同的值的文件夾變量捫作爲

1:values  
    -dimens.xml  
    <dimen name="image_email_width">45dp</dimen> 
     <dimen name="image_email_height">35dp</dimen> 

2:values-xlarge 
-dimens.xml 

    <dimen name="image_email_width">90dp</dimen> 
     <dimen name="image_email_height">70dp</dimen> 

然後設置你的ImageView爲

<ImageView 
    android:id="@+id/portal" 
    android:layout_width="@dimens/image_email_width" 
    android:layout_height="@dimens/image_email_height" 
    android:layout_alignLeft="@+id/forts" 
    android:layout_below="@+id/forts" 
    android:src="@drawable/portal" /> 
1

使用不同類型的圖像即LDPI,MDPI,華電國際,xhdpi,xxhdpi。

1

對於不同的屏幕尺寸和不同的密度圖像將有所不同。 對於圖像嵌入imageview的USEE,

android:scaleType="fitXY" 

如果你希望你的ImageView類似的所有設備,你需要爲不同的屏幕大小和不同的相似圖片LDPI,華電國際,MDPI不同的密度不同的佈局文件夾。

相關問題