I am developing photo Editor in android Studio . I have images and icons on my screen which is not fit to other screens(different sizes). I have included following support screen code in my manifest.xml file
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
I came to know that density independence is the way to get rid of this. I don't know how to proceed further .please help me what are the steps to make my App density independence? activity_main.xml
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical|center"
android:background="#403E3E">
<LinearLayout
android:layout_marginTop="30px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<SeekBar
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:max="200"
android:progress="100"
android:id="@+id/seekBar1" />
</LinearLayout>
<LinearLayout
android:id="@+id/middle_layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:id="@+id/imageView2"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="@drawable/ic_launcher"
android:layout_gravity="center_vertical"
android:background="#ff0e0e0e" />
<SlidingDrawer
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:content="@+id/content"
android:handle="@+id/handle"
android:id="@+id/slidingDrawer"
android:orientation="horizontal"
android:alpha="0.5"
android:layout_gravity="right|top">
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#11111111"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/brighticn"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:background="@drawable/brighticon"
android:layout_gravity="center_vertical" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/filtericn"
android:background="@drawable/filters" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/handle"
android:background="@drawable/move" />
</SlidingDrawer>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_gravity="bottom">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_gravity="bottom"
android:background="#ff030101">
<LinearLayout
android:id="@+id/sublayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ff030101">
<Button
android:id="@+id/buttonhide"
android:text="txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
To truly be able to have a density independent app, you need to provide your resources in different resolutions. Android is really smart on handling those.
When adding images you should create smaller images, or larger images, based on the format of the screen you want to support and put them in specific folder for that format. Something like this:
This would make Android use
drawable/icon.png
when you have any other screen density thanhdpi
. But will usedrawable-hdpi/icon.png
for that specific type of screen.To understand this better, you can read this very detailed guide from the Android docs: http://developer.android.com/guide/topics/resources/providing-resources.html