Reputation: 25
I want to align an image view which is displayed same for all android screens expect for Android tab screen. Different alignment of imageview is noticed for imageview when app runs on emulator or live device. how do i align them properly??
Here is my 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>
Upvotes: 1
Views: 123
Reputation: 392
You can have set variable dimen in different values folder as
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>
Then set your Imageview as
<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" />
Upvotes: 2
Reputation: 3103
Use different types of images i.e. ldpi, mdpi, hdpi, xhdpi, xxhdpi.
Upvotes: 1
Reputation: 508
For different screen size and different densities image will differ. For fitting the image into imageview usee,
android:scaleType="fitXY"
If you want your imageview similar to all devices, you need to create different layout folders for different screen sizes and different images like ldpi,hdpi,mdpi for different densities.
Upvotes: 1