Im trying to display an admob ad which completely covers the width of screen (like SMART_BANNER), and 90dp constant height.
using this code, i can set the height to 90dp, but how can i make the ad width fill the width?
AdSize adSize = new AdSize(deviceSpecificWidth, 90);
According to this, these are the standard sizes of SMART_BANNER
Screen width x 32|50|90
can i force the smart banner to only use 90dp height in every device?
I would suggest to use the newly introduced AdMob Adaptive Banners. They don't require adjustments on your side and they utilize all the width available and keeping the aspect ratio (which was a problem before).
Embed them into a FrameLayout like following
<FrameLayout
android:id="#+id/adFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center|bottom" />
Related
i am using a Matrice 300 RTK and a H20 camera, this camera have 5184×3888 resolution for phtos that is 4:3 ratio and the video have 16:9 ratio, so in my app i need to show the camera, in mode video all ist ok but when i change to mode photo whit you CameraControlsWidget the image that show the dron are so stretch horizontally, them when i use the DJIPilot this effect dont show, in this app the borders of image are in black for show a correct aspect ratio of 4:3 i put the code of mi xml if you need anything more for make a solution say me and thank in advance.
<TextureView
android:id="#+id/camera_live_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
/>
<dji.ux.widget.FPVOverlayWidget
android:id="#+id/camera_live_view_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
I'm using something like that to present my logo or user profile picture:
<ImageView
android:id="#+id/logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/circle_bg"
android:src="#drawable/account_circle_grey"
android:layout_gravity="center_horizontal" />
#drawable/circle_bg:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#color/colorWhiteOpacity"/>
<size
android:width="100dp"
android:height="100dp"/>
</shape>
and #drawable/account_circle_grey is just an image I took from MaterialUI(the black 192x192) and used Final-Android-Resizer.
The problem is that I get something like that:
Basically the problem is that when the user clicks and pick a picture, I use glide to load the picture to replace the default #drawable/account_circle_gray but as you can see the padding is gone:
The picture takes the full space, as it should!, what I wanted to add is padding="5dp" and that will give a bit of padding between the background and the Glide loaded user picture, the problem is that there is already a weird padding to #drawable/account_circle_grey, I noticed however that not all drawables get the padding, when I chosen an old picture I used as a full page background I didn't get the padding, maybe I can force android to pick bigger picture, why do I get this padding?
Edit:
To clerify I used this tutorial to try all possible(scaleType+adjustViewBounds) values but nothing worked.
This is likely happening when you're using images that are physically smaller than the size of your ImageView. You can scale the image to fill the space or use a larger image. A mix of both is likely the best solution.
To achieve the former of the two, try this:
<ImageView
android:id="#+id/logo"
android:layout_width="90dp"
android:layout_height="90dp"
android:background="#drawable/circle_bg"
android:src="#drawable/account_circle_grey"
android:layout_gravity="center_horizontal"
android:scaleType="fitXY"
android:padding="5dp" />
Notice that I reduced the width and height by 2x the padding. That is because adding padding to a view increases the entire view's size by the size of the padding. In this particular case we're adding 5dp to the left, to the right, to the top, and to the left. This means we must subtract left and right from the width, and top and bottom from the height.
set the scaleType of your ImageView to centerFit or you can add only high dpi drawable to your drawables
thanks for the answers, the problem was so obvious but I made it complicated, although I used many "account_circle" images, what I didn't think was that they all comes with a transparent padding, so if the image is 192x192 for instance it's actual size is about 182x182 with 5px transparent padding on each side, anyway the simple solution is to open it on photoshop, go to Image>Trim and that's it.
I am working on an App which shows images (by capturing using camera or choose from gallery) in some activity. The problem I am facing is showing images of different sizes. The actual size of image is very big even those which are captured by camera of same phone are large in size. So if I show them in an ImageView the get stretched.
I have seen in some apps like Facebook, when image is displayed in Full Screen mode, it maintains the aspect ratio I guess. The whole image, whatever its size may be, is shown in the screen but it doesn't get stretched. The image automatically adjusts its height and width as per the need. How to achieve the same functionality?
How to make ImageView which would be able to adjust its height and width (maximum already defined) as per the need.
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="matrix"
android:src="#drawable/defaultimage"
android:padding="10dp" />
You need a different android:scaleType in your layout. The ImageView.ScaleType documentation lists the different ones that are available. It sounds like you probably want to change matrix to fitCenter in your example.
I would like to scale my application layout to the screen size.
When I run it on a 4 inch emulator (but I don't display the actual screen size, so it looks larger)
It looks like this,
However when I run it on a larger emulator with the actual screen size, it looks like this,
My layout.xml is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="false"
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" >
Followed by the images and buttons.
The width and height of all images and buttons are,
android:layout_width="wrap_content"
android:layout_height="wrap_content"
I guess what I am asking is how to scale the layout to fit the size of the screen?
Like the way it fits the screen when the screen size is 4inch in emu but is not displaying to actual screen size.
As I want to be able to use the application on larger tablets.
You can use different layouts for different screen sizes.
And by the way...are these images from an emulator??
I hope you are not using "scale to actual size" while running your emulators...
Difference in pixel and resolution may also lead to this
In your relative layout, do this
android:layout_width="match_parent"
android:layout_height="match_parent"
This will make the layout fill the screen.
EDIT:
For the ImageView, use
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerInside"
This would stretch the image to fit the width (hopefully).
The connect ImageView is a tricky one. Not sure what will work for that. You'll need to experiment with the scaleType attribute.
For the buttons, increase the text size and set the layout_width as wrap_content. The buttons will get bigger.
How can I prevent my bitmap from being scaled automatically in an ImageView or ImageButton if the view or button is stretched using "fill_parent" or using "weight"?
This will be useful, for example, to create a 4-button toolbar at the top of the screen where the buttons are equally spaced, but the images inside the buttons keep getting streched even if I use scaleType="center", which should prevent scaling according to the doc, but it doesn't.
Any insight is appreciated!
Thanks,
I have found that when using android:background automatically scales the image you are using there to the size of the View.
I tried using the android:src to put the image in the view. The image did not scale, but I could not get the image to center relative to the size of the View.
So I tried making the whole Button it's own relative layout and this is what I used:
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ImageButton android:id="#+id/ImageButton01"
android:layout_height="fill_parent"
android:layout_width="fill_parent"></ImageButton>
<ImageView android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/cardback1"
android:layout_centerInParent="true"></ImageView>
</RelativeLayout>
The ImageButton is in the background and will always be the same size as the layout.
The ImageView however will always stay centered in the RelativeLayout and will not scale.
This way the RelativeLayout itself can grow and move and the Image on top of the button will always stay the same size, but the button will grow. The image will however shrink if the Layout becomes smaller than the image itself.
I think that's what you were looking for. There may be a better way to do this, but this is all I can come up with right now.
Simply modify your drawable, apply a larger transparent background. Say my drawable in hdpi is 41*48 px icon.png . I created a new image 60*60 px with a transparent background , copy-paste the previous icon.png and save under the same name. This way you don't need to touch your layouts .
Then you can check the button zone larger if you apply a non transparent android:background:
<ImageButton android:id="#+id/widget_open"
android:src="#drawable/icon_widget_arrow_up"
android:background="#ff777777"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageButton>
Apply the previous and new drawable to android:src , you should clearly see ImageButton area.
By the way, I am running the app in compatibility mode.
If the image is scaled, make sure you are not running your app in compatibility mode (for instance if you target Android 1.5/1.6 without supporting multiple densities and you run the app on Android 2.0.)