Android - Images showing at different sizes on different devices - android

I am coming from the world of iOS so bear with me. I am getting a little confused about image scaling and why my images are appearing different sizes on different devices.
My app uses a large background image and in the middle are placed a number of other images in a stacked order. They are placed in a colored area which is part of the background image.
When viewing my layout in the Graphical View different phones will show the individual tile images at different sizes. Sometimes they will all be contained within the dark grey background block and sometimes they overflow. Sometimes they are too small.
I am creating my background image:
<ImageView
android:id="#+id/backgroundImageView"
android:layout_width="1000dp"
android:layout_height="1000dp"
android:layout_gravity="center"
android:contentDescription="Background Image"
android:scaleType="centerCrop"
android:src="#drawable/background2" />
I gave it specific height and widths, otherwise the background image is way too small, much smaller than its actual size.
Example of the two left individual images:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="-7dp" >
<ImageView
android:id="#+id/digit5top"
android:layout_width="wrap_content"
android:layout_height="37dp"
android:src="#drawable/top" />
<ImageView
android:id="#+id/digit5bottom"
android:layout_width="wrap_content"
android:layout_height="37dp"
android:layout_marginTop="38dp"
android:src="#drawable/bottom" />
</RelativeLayout>
How can I get my background image and individual tile images to appear the same size/proportion on all devices?

Related

Fresco, how to scale images for different devices

I'm building an app with the Fresco library, by Facebook.
I'm having issues trying to understand how I should implement a view using Fresco, if my App will be usable among different devices. As you can see in the images attached, I have a Nexus6, a NexusOne and a Nexus7.
All of them have the same Fresco Drawee, (200dp x 200dp). As I've read through the documentation of Fresco, it is necessary, and mandatory, to fix the image size. However I'm having trouble understanding how can I achieve something as simple as having an ImageView using 50% of the image width using Fresco.
The desired result would be to have an image that uses half of the screen (in terms of width), and leave the rest of the space for the different texts (title+descriptions shown).
Normally I would do this using weight's, however I'm not sure how to achieve this with the library, or what the best practices would be.
Based on this question (and documentation), I'm not sure if adding a listener is the best option. I'm just failing to understand how Facebook or other applications who use this library, do it for different devices.
Thanks in advance
The code shown of this images is basically the following:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/my_image_view"
android:layout_width="200dp"
android:layout_height="200dp"
fresco:actualImageScaleType="focusCrop"
fresco:backgroundImage="#drawable/user_icon"
fresco:fadeDuration="300"
fresco:placeholderImage="#color/common_action_bar_splitter"
fresco:placeholderImageScaleType="fitCenter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/my_image_view">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Title 1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#color/menu_color"
android:text="Description 1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Title 2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#color/menu_color"
android:text="Description 2" />
</LinearLayout>
</RelativeLayout>
UPDATE:
I also don't know how to get a full-screen image. If we must either specify the dimensions, or use match_parent, but using match_parent on both would use the whole parent, how can I get something like the image showing the Facebook image?.
I believe #Gueorgui Obregon's is a good idea, however I'm still wondering if the problem is the design pattern of using 50% of the screen for a picture. For instance, take 2 cell phone models with the same dimensions (MDPI for example), but one of them is a little bit wider than the other. Using the dimensions approach I'd get than on one mobile it takes half of the screen, but on the other one, it would take a little bit more/less.
In summary: Where is the problem? Is thinking in percentages a bad idea when designing views? Should I tell my designer that it's a bad design idea for android to use percentages? More importantly, how can Facebook achieve something like the last photo (where the pictures use a ~33% of the screen)?
Your could use dimensions.xml for different values folder for different screens.
res/values/dimensions.xml
res/values-sw600dp/dimensions.xml -> 7+ inches
res/values-sw720dp/dimensions.xml -> 10+ inches
Add on each dimensions the desire value
res/values/dimensions.xml
<dimen name="my_image_view_width">200dp</dimen>
<dimen name="my_image_view_height">200dp</dimen>
res/values-sw720dp/dimensions.xml
<dimen name="my_image_view_width">400dp</dimen>
<dimen name="my_image_view_height">400dp</dimen>
Then simply use #dimen/my_image_view_width and #dimen/my_image_view_height in your SimpleDraweeView like this
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/my_image_view"
android:layout_width="#dimen/my_image_view_width"
android:layout_height="#dimen/my_image_view_height"
fresco:actualImageScaleType="focusCrop"
fresco:backgroundImage="#drawable/user_icon"
fresco:fadeDuration="300"
fresco:placeholderImage="#color/common_action_bar_splitter"
fresco:placeholderImageScaleType="fitCenter" />
Hope this helps!!

Background resized by Navigationbar

i am developing an Android App and want to use a picture as background in my Activity. On devices without the Navigationbar (Devices with a Homebutton) it looks great. When the device has no hardware buttons, Android scales the backgroundpicture because the height of the screen is reduced by the Actionbar.
My Question is not about xhdpi, hdpi and so on, but about handling for 16:9, 16:10...
How can I solve this?
How are you specifying the background image in your layout? If you are using an android:background attribute on a View then you will have no control over image scaling. It sounds like this is what you are doing.
Instead create an ImageView with appropriate scale type. For example I use the following structure:
<FrameLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:focusable="false"
android:src="#drawable/bg" />
<!-- Rest of your layout -->
</FrameLayout>

Android 9 Patch - 'bottom' area not showing?

Am running into something that I have spent hours trying to get working. I have tried searching but what stumbles me is how to search a resolution for this as it is a strange and apparently not-so-common issue?
All I want is to be able to stretch a 'dash of paint' vertically using the y-axis scalable area marked as a single pixel on the left. My 9patch file is below:
I have gotten this to HALF-work as can be seen (ignore the top horizontal line, this is a separate imageview):
As you can see, I am missing what I call the 'Non-scalable end' which is basically the static part of the 9patch file (unmarked on left y-axis scalable area)
The code in the layout is simple:
<ImageView
android:id="#+id/repeater"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/PlayersList"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/PlayersList"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/repeater" />
(file is named repeater.9.png and stored in res/drawable-xhdpi)
Note: For some reason this works exactly as required in the 9-patch tool, but doesn't seem to work in eclipse (earlier screenshot):
Is this the effect you were looking for ?
I have attached images for all drawables let me know if it worked.
You can use http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html
to generate 9 patch images instead of making it form default tools.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_example"
android:scaleType="fitXY"
android:contentDescription="#null"
android:adjustViewBounds="false" />

android: long loading time for background of imagebutton

I am designing an app of which there is an index page that link to several content layouts, and each layout has an imagebutton in the middle of the screen. The code for the ImageButton is as follows:
<ImageButton
android:id="#+id/image_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="#drawable/transparent_btn"
android:focusable="false"
android:gravity="center"
android:scaleType="fitCenter"
android:src="#drawable/ice_cream400" />
The ice_cream400 is an png of 400*400px and around 148KB.
Question:
I always come across with problems about images.
The png are already put under the drawable-xhdpi folder as suggested from research as the system will shrink the size automatically.
I am running the app in real phone device and discover that from time to time loading the content layout takes a lot of time (around 2 sec). How could the performance be improved? Need fetching the dimension of the screen and scale down before import? (the imagebutton would occupy around 70% of the screen)
Thanks!

Supporting multiple Screen sizes with Button design

I have created a button in Photoshop. The problem is that when I test app from a big screen phone everything is good, but when I test in smaller phone then button is very big. How can I make good size button for every phone sizes?
I suppose by "I designed a button in Photoshop" you mean that you designed its background-image.
The size of a Button is actually not necessarily dependent on the size of the background image. You can control the size of your button via its properties that can be set in the layout.xml file (or in code).
In this simple example the Button will always use up exactly half of the parent layouts width (LinearLyout).
(Watch the "weightSum" and "weight" properties).
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:weightSum="2">
<Button
android:id="#+id/btn1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Button"
android:layout_weight="1" />
</LinearLayout>
Of course, there are many more ways and properties of how to adjust your layout to different screen sizes, this should just give you a brief example of how it could be done.
For more information, check out this tutorial from the Google-Android-Developer page:
Supporting Multiple Screen Sizes (especially Density-Independence should be interesting for you)
http://developer.android.com/guide/practices/screens_support.html

Categories

Resources