android - 如何为所有安卓屏幕对齐 ImageView

标签 android imageview alignment

我想对齐一个 ImageView ,它在除 Android 选项卡屏幕之外的所有 Android 屏幕上显示相同。当应用程序在模拟器或实时设备上运行时,会注意到 imageview 的不同对齐方式。我如何正确对齐它们??

这是我的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: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" />

关于android - 如何为所有安卓屏幕对齐 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29841406/

相关文章:

html - 如何垂直对齐字形?

Android:如何在不调用 onCreate 方法的情况下从服务后台恢复应用程序?

android - 丢失包裹

android:用 picasso 创建圆形图像

android - 从 ImageView Android 的左边缘裁剪

swift - 如何将图像连接到另一个 ViewController 并将其显示在 ImageView 中?

android - 生成签名 APK : Errors while building APK Android Studio

android - 在 Android 中以编程方式操作 XML 布局

html - 如何使用 CSS 为所有浏览器垂直居中 div 元素?

javascript - Google reCAPTCHA v2 忽略 CSS 对齐