[英]How to align an image-view for all android screens
我想對齊一個圖像視圖,該圖像視圖對於所有期望用於Android選項卡屏幕的android屏幕都顯示相同。 當應用程序在模擬器或實時設備上運行時,imageview會注意到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" />
使用不同類型的圖像,即ldpi,mdpi,hdpi,xhdpi,xxhdpi。
對於不同的屏幕尺寸和不同的密度,圖像將有所不同。 為了使圖像適合imageview用戶,
android:scaleType="fitXY"
如果要使圖像視圖與所有設備相似,則需要為不同的屏幕尺寸創建不同的布局文件夾,並為不同的密度創建不同的圖像(如ldpi,hdpi,mdpi)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.