Image Button re-sizing issues - java

I have created a 6x7 board for a connect 4 game.
All the empty cells are image buttons.
When in portrait mode the board looks like this.
However, when I change orientation to landscape it looks like this.
The layout for one of the empty cells (Which I repeat) is
<ImageView
android:id="#+id/r6c4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/arrow4"
android:layout_centerHorizontal="true"
android:contentDescription="#string/emptyBox"
android:src="#drawable/empty"
android:visibility="gone"/>
I am very new to android, can anyone point out how I may be able to resize the images to fit the landscape screen?
Thanks

Related

Aspect ratio on mode photo H20

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" />

Adding a circle on an imagei n Android

I have on a project the following Image defined in the Layout-Main:
<ImageView
android:id="#+id/imageViewCompass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/compass"/>
This Image View represents a compass and I would like to add over the image an indication showing the Direction to follow.
Actually the image rotates to indicate the North direction
You can make images for each of the directions and change them according to your needs in the MainActivity.

TextView is cut off when applying BlurMaskFilter

I want to blur the text of a TextView, but the text is cut off left and right.
Image of the cut off text
I tried to increase padding, margin. Changed gravity, Enabled/disabled font padding. Set a fixed height, lowered font size etc. All to the same result: The sides were cut off.
The setting of the mask filter is just two lines:
textView.paint.maskFilter = BlurMaskFilter(radius, BlurMaskFilter.Blur.NORMAL)
textView.postInvalidate()
This is how my XML layout looks like:
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="-1dp"
android:includeFontPadding="false"
android:layerType="software"
android:textSize="48sp"
tools:textColor="#color/solid_white"
tools:text="132" />
I'm looking for a solution to see the text fully without cutoffs on the edges.
Remove this attribute from your <TextView> tag:
android:layerType="software"
Hardware acceleration is required for views to draw outside of their bounds. Note that padding doesn't help here because view contents are clipped by padding as well.
After attempting a ton of alternatives, using a LeadingMarginSpan.Standard(margin) to offset the text did the trick. I overrode the class and added the blur mask there rather than using a MaskFilterSpan.

Android drawables sizes not scaling

Alright, this seems like it can be a very confusing question but I'm going to try anyway.
I am developing an application right now, and the only thing that you should know is that there are two drawables in this application.
Both drawables have the same exact width. There is a background drawable that obviously goes in the background of the XML. And then theres an ImageView of a simple line. This line is a drawable aswell.
On some devices/emulators, the line is not the full width of its resolution. Despite the fact that both drawables have the same exact width. And both are viewed in the same portrait mode.
Is there any fix to this? Basically this line moves upwards and represents something important, but I can't have it be a different size than the background. I really don't fully understand why the background with a width of 600, and a line with a width of 600 isn't the same size on some devices. Despite putting both drawables in the Drawable folder, and not one for the different resolutions. I currently do not have any screenshots, I will make some if need be, but I hope someone knows why this problem is bugging me and if I am doing something wrong. Can I perhaps tell the application that its resolution must be 800x600, so that all devices that are capable of showing that many pixels, will do so? If this is possible, how do I do this? I hope someone is able to help
a newbie out :)
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:gravity="top"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-60dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:src="#drawable/line" />
</RelativeLayout>
Try setting the scaleType of the imageview to fitXY.
android:scaleType="fitXY"

Re-scaling layout to fit screen

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.

Categories