2015-04-24 29 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不同的密度不同的布局文件夹。

相关问题