如何为所有android屏幕对齐图像视图
我想对齐一个图像视图,除了android选项卡屏幕外,所有android屏幕都显示相同的图像视图。当应用程序在emulator或live设备上运行时,imageview会注意到imageview的不同对齐方式。如何正确对齐它们 这是我的活动。xml如何为所有android屏幕对齐图像视图,android,imageview,alignment,Android,Imageview,Alignment,我想对齐一个图像视图,除了android选项卡屏幕外,所有android屏幕都显示相同的图像视图。当应用程序在emulator或live设备上运行时,imageview会注意到imageview的不同对齐方式。如何正确对齐它们 这是我的活动。xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
<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>
使用不同类型的图像,即ldpi、mdpi、hdpi、xhdpi、xxhdpi。使用不同类型的图像,即ldpi、mdpi、hdpi、xhdpi、xxhdpi。对于不同的屏幕大小和不同的密度,图像将有所不同。
要将图像适配到imageview中,请使用
android:scaleType="fitXY"
如果希望imageview与所有设备类似,则需要为不同的屏幕大小和不同的图像(如ldpi、hdpi、mdpi)创建不同的布局文件夹,以获得不同的密度 对于不同的屏幕大小和不同的密度,图像会有所不同。 要将图像适配到imageview中,请使用
android:scaleType="fitXY"
如果希望imageview与所有设备类似,则需要为不同的屏幕大小和不同的图像(如ldpi、hdpi、mdpi)创建不同的布局文件夹,以获得不同的密度 您可以将不同值文件夹中的变量dimen设置为
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>
1:值
-dimens.xml
45dp
35dp
2:值xlarge
-dimens.xml
90dp
70dp
然后将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" />
您可以将不同值文件夹中的变量dimen设置为
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>
1:值
-dimens.xml
45dp
35dp
2:值xlarge
-dimens.xml
90dp
70dp
然后将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" />
您可以使用drawable文件夹和dimen文件夹放置不同的图像mdpi、hdpi、ldpi、xhdpi等。您可以使用drawable文件夹和dimen文件夹放置不同的图像mdpi、hdpi、ldpi、xhdpi等