我想对齐一个 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/