Navigation bar 48dp on every screen - android

I'm trying to make an android app. But I'm having many troubles with the design. I want to make a navigaton bar with a height of 48 dp on every screen. I know which height in px I have to use but I don't understand which width because every screen has another and it dosen't scale right. I just want a navigaton bar in one color with a height of 48dp and a witdh which scales to the screen so that it is from the left all way to the right with a continious height of 48dp. I hope you understand my problem if not please ask. Thanks for your time!
FOR PEOPLE WITH SAME PROBLEM:
android:scaleType="fitXY"

The accepted answer is deprecated. Please use match_parent instead of fill_parent

There is one more attribute
android:gravity="fill_horizontal"
(Grow the horizontal size of the object if needed so it completely fills its container.)
FOR HELP

Try using android:layout_width="fill_parent".

Related

Custom Actionbar imageview needs to fit

I have a very simple question.
I have been asked by my company to make the actionbar just a simple imageview. So no icon, no title and no buttons at all. I've created a custom actionbar, and the imageview is up there just fine. I have attached a link to an image of my layout, and the emulator on the right. They want the imageview to be like it is in the layout. But in the emulator it comes up small.
My question is simply: is there a way I can make the imageview fit like it is in the layout there, and of course have it fit for different devices too - or, must the graphic designer simply create a banner that fits the size of an actionbar. If so, I looked at android's iconography and saw the height should be 48dp. but what about the width? And won't different devices have different width? Or will i be able to make sure it is stretched across the whole width of the screen. I've tried match parent in my xml but of course it won't do anything now because it doesn't want to stretch the height of the actionbar.
Thanks alot
https://www.dropbox.com/s/1tek8ptar3j76d4/Screenshot%202015-02-27%2009.55.30.png?dl=0
Get your graphic designer make you a 9 patch png that will expand in the middle while keeping its proportions then simply add this line of code:
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.your_nine_patch_png));
More on nine patch images here: http://developer.android.com/tools/help/draw9patch.html
Here is the trick!
yourImageView.setGravity(Gravity.FILL_HORIZONTAL);
Happy coding! ;D

Android Responsive Design Titanium

I've been working on an android application on Titanium lately and i've come upon an issue.
What i'm struggling with is making a specific view responsive.
I want to show like 15-20 buttons on a view but i don't want it to be scrollable.
Now if i use around 50dpi which is the recommended for buttons on some smaller screens i miss some of them.
How should i approach this? Should i use % of the device width and height which i get like
function PixelsToDPUnits(ThePixels) {
if ( Titanium.Platform.displayCaps.dpi > 160 )
return (ThePixels / (Titanium.Platform.displayCaps.dpi / 160));
else
return ThePixels;
}
Ti.App.deviceWidth = PixelsToDPUnits(Ti.Platform.displayCaps.platformWidth);
Ti.App.deviceHeight = PixelsToDPUnits(Ti.Platform.displayCaps.platformHeight);
Should i create say 4-5 different views and load the right one according to the user's DPI?
What's the most correct way to approach this.
THanks
I don't know if it is what you want to archive but you can work with android:layout_weight.
If you got 2 Buttons and both have a weight of 1 each of them will always cover 50% of the screen. Weather or not my answer helps please post your xml so we can be more specific about your Problem.
This is what I follow:
Get the aspect ratio(width/height) of the button so that it is not squished or stretched.
Divide the available height by the no of buttons. Add some top and/or bottom padding. This is the height of each button
Width of button=height*aspect_ratio
This way you can fit buttons on any screens including tablets

Android XML ImageView

I've been trying to find an answer to this all of last evening with no luck so I decided to come ask here. I just started getting into front end dev for Android apps and I'm trying to do something really simple that just doesn't work. All I want to do is add an image on the screen and be able to resize it EXACTLY what size I want regardless of proportions. This is the code I'm currently using inside a relative layout:
<ImageView
android:layout_width="400dp"
android:layout_height="200dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/statsus_logo" />
My image is a horizontal rectangle. When I first add it, it shows up inside a small square centered with a bit of padding all around. When I make the width 400dp that square appears to strech almost 100% across the screen however the logo stays the EXACT same size, centered vertically and horizontally inside this imageview container. When I increase the height of the imageview, the logo increases its size but almost as if it was taking the height and using it as a width. I feel like what its trying to do right now is use the height as its width and the only time when its width is the value i put in, is if the height is also the same value and even then there's some extra unwanted padding.
Again, all I want is for this damn image to be the size I tell it to, so if I want it 5dp wide and 100dp tall, it does just that. Can anyone please help? Thank you very much in advance.
Try to add this attribute to your imageview
android:scaleType="fitXY"
Scale type reference
android:scaleType="fitXY" is the way to scale your image however you want without keeping your proportions however my issue was a little bit different... I'm using android studio and for some reason the settings I was using to "add a new image asset" was making my image act the way I described it above... if I just add an image manually by just click and dragging into the folder, then the image works the way I want it... so long story short, the issue was with how I added my new image asset
thanks to everyone for all of your answers and help!

ImageView of width larger than the screen width

I'm implementing an animation which displays scrolling image. I need to display a image in its original size even if the width is more than the screen width and then have to animate it.
Please tell me how to place image like that.
Check out the different scaletypes here: http://bon-app-etit.blogspot.be/2014/01/imageview-scaletypes.html
I think you'll need android:scaleType="centerCrop"
There are couple of things you can do and it depends on the behavior you want to implement. A quick two solutions are:
You can use ScrollView with your image in it and by touching it you can move it left or right. Example solution you can find here: Displaying an image larger than the device's screen
You can use absolute layout (although this layout is already deprecated) and place your image in it. Make the layout width and height be the same as your image.
The animation can be done with many ways:
1. On touche event handling
2. Fling with scroller or gesture detector
3. Accelerometer tilt
Hope it directs you to the right solution.
Try using scaleType in ur imageview xml,
android:scaleType="fitXY"

Android RatingBar problem in device

Hi I am using Rating Bar in my App. When I try it in emulator the rating bar is fully visible. (i.e) I am able to see all the five stars, but when I try it in my droid mobile, I am able to see only four stars. Can anyone suggest me a solution for this.
This can be layout issue. In droid mobile if your layout is not able to stretch properly , and you have specified certain width to rating bar, stars(layout) gets truncated. Arrange layouts using layout weights, that might solve your problem.
Do you have any padding on the RatingBar element? I just had a similar clipping issue when layout_width of my RatingBar was set to wrap_content and I had paddin_left and padding_right defined.
Removing the padding removed the clipping
The problem seemed to be because of a totally different situation.
The Default star of the Rating Bar doesn't reduce their size to adjust the layout. What ever is the screen size it has the same size(Big, small etc). So if we set the Star size to big, it will just make the star to hide from the layout. So the best solution is to make the layout size enough to fit the number of stars you are about to provide.
If not provide small style star to your Rating Bar if your layout can't accomadate big star style.

Categories

Resources