Hi I am stuck with an issue and need some expert suggestions. I have a custom circular progress par whose boundary rotates as an animating light in my splash screen
It looks like this:
The boundary light continuously rotates till splash screen is there.
Now my splash screen has a background image which has a circle drawing at upper half of image:
It looks like this:
Now my circular progress bar should fit on that background circle boundary. What ever i do, it fails for some phone screens (circle is misplaced).
How can i fit into background circle and it can work on all phones and tablets.
Please let me know if further clarification is needed.
This is how I have defined circular progressbar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/my_splash_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/splashscreen" />
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminateDrawable="#drawable/my_progress_indeterminate"
android:visibility="visible"/>
</RelativeLayout>
I think you need to change the style attribute and set your android:layout_width="match_parent". The problem is you are setting the style to large which by default has its size pre-defined. Further in your width and height attribute you are trying to resize it. So this might be the problem.
Try out with the HoloCircular ProgressBar is a Custom View implementation for Android.
Checkout the HoloCircular ProgressBar which might help you.
Other Library that you can use are as below:
1) Progress Wheel
2) ProgressBar
3) Customize the Spinner
Thanks.
This link helped me resolve the issue to some extent as it now suppots majority of devices. Still I could get a general solution to the problem. But I can consider this as answer:
Application Skeleton to support multiple screen
Related
So I'm working on Pacman for Android as a learning exercise. I've got the background set in my activity layout, but I'm having trouble making the background fit properly.
I've tried centerCrop and fitXY, with different results, neither of which work exactly. I want to stretch the view to the dimensions of the screen. It appears however that the image view is restricted to the center, like I have 3 imageviews ... but I have only one.
Any thoughts? Do I have to do some of this in code?
Thanks!
<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:background="#000FFF"
tools:context="srg.pmd.GameActivity"
>
<ImageView
android:id="#+id/emptyPacman"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/blank_screen"
android:scaleType="fitXY"
/>
First screenshot is fitXY
Second is centerCrop
The image you are using must be 320x480 then only the image will fit the screen other wise it will get distorted here is a link for more info about the image size Android: Background Image Size (in Pixel) which Support All Devices .hope it works for u
Well, nuts to me. The actual png file was wrong -- it was a lot wider than I assumed. Taking a closer look with an image editor revealed the problem.
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>
I have an activity that includes a striped background image. Click to enlarge – this is the original image I'm using. There's also a version with a logo for another activity.
It looks fine as is. I set it as a background in the activity through XML, something like this.
I need the hack as an ImageView to be able to properly centerCrop a logo in the background, but this is irrelevant to the issue, as it persists when setting the background for the RelativeLayout and removing the ImageView.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/background_striped" />
Note that since there has to be a logo inside the image, I can't stretch it artificially or have it repeat.
In the layout preview screen, it looks like this:
In the emulator, it looks like this:
As you can see, it looks quite bad, compared to how I'd expect it:
Naturally, I've created versions of the striped background for all display resolutions (from ldpi to xhdpi), but they always seem to be scaled in a pretty bad way.
Is there any way to get the background scaled in a higher quality? Just using the xhdpi version won't result in better quality—it will just make the scale result worse and more washed out.
For scalable drawables it is better to use a 9-patch. You can create one with your small striped background image using the android 9-patch tool:
http://developer.android.com/tools/help/draw9patch.html
Try using repeat. I tested it and it seems to look fine.
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background_striped"
android:tileMode="repeat" />
So I'm trying to put an image inside a scrollview and have the image stretch to fit different sized screens. It'll stretch horizontally, but vertically it always comes out messed up.
I've read so many pages of people with similar problems, but their solutions never work for me. I've tried every different combination possible using different scaleType,layout_width and layout_height, along with trying changing other things around. The closest I've gotten to getting it to work is shown in the code below, using scaleType="centerCrop". It's the only one that stretches the image vertically in ratio, but it cuts off a big chunk of the image from the top and bottom, it'll scroll up and down the image, but only the middle part shows.
The image is a 480x5500 jpeg, if that matters. Originally before I started messing with all that, the app worked just fine on my phone, but then later I realized the image was crunched when I tried it on a tablet. There's gotta be a way to do this in the xml right? I really don't want to have to do things with the image in the java code part. Also I'm hoping to be able to do this using just one image, I don't want to have use a different image for different screen sizes. Please help, thanks.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/paper" />
</ScrollView>
may be this help you,
make both height and width wrap_content of ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
and no need ScrollView here.
Try using custom ImageView like AspectRatioImageView mentioned here:
https://stackoverflow.com/a/4688335/944070
the next sample is more than what you ask for :
http://www.androidviews.net/2012/11/photoview/
https://github.com/chrisbanes/PhotoView/tree/master/sample
https://play.google.com/store/apps/details?id=uk.co.senab.p
hotoview.sample
it fits the image to the screen , plus it allows to zoom in/out using pinching gestures.
So I have a PNG as shown below. The white inner in the image is transparent.
My problem is that this image isn't really scalable for different size screens on Android devices.
I would like to know how I can do this either in code or preferably, xml. Basically I am looking for a grey square with a transparent circle inset.
Also, there is a nice effect on the inner border of the grey, is this possible in code?
I know how to do the inverse (bitmap with rounded corners) but how would I do this? Any ideas appreciated, thanks.
Edit:
So, the only thing I have tried is android:scaleType="centerCrop"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:scaleX="0.7"/>
</LinearLayout>
Can you try this one.
It's not clear from your question why the image is not scaling properly for different screen sizes.
Using NinePatch PNG format you have full control how the image scales. For example, this enables you to force that only the image gray areas are extended, keeping the circle format, if that is your problem.
The documentation can be found here: Draw 9-patch
Regards.