TextView going out of screen - android

I have a TextView in a RelativeLayout that sometimes is partially out of the screen.
the problem is that instead of just being partially out of the screen its sizes change so that the entire TextView still remains on the screen.
I want to know how to disable that change.
EDIT: this is my TextView XML
<TextView android:id="#+id/neighborImage"
android:drawableBottom ="#drawable/icon"
android:text="Temple Bar"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="matrix"
/>
EDIT2:
The icons you see on the radar are the TextView. The reason I'm using TextViews is because there will be text above the icons eventually.
So, as you can see I've uploaded 3 pictures.
These 3 pictures describe a zoom in, and as a result the icons are moving. If we will look at lower right picture we can see that when it reaches the end of the screen, the image width is changed and as a result the image is pushed to the right in the third picture you can see how it continues. i want to have the same result as when using ImageView, in this case the picture will just be partially out of the screen it it's size will be the same.
Thanks.

Check your xml. You are likely setting layout_width as "wrap_content", you want "fill_parent"
Alternatively, post the xml in question.

Related

ImageButton Scaling issue within ConstraintLayout

Just putting it out there I rarely work with .xml so I am sorry for the basic question. I have looked around for other solutions but none really seem to be helping my issue.
So I am adding an ImageButton to my login screen, and the actual image is too large. Here is what the image looks like when I place it in and make no adjustments.
The Login button is too big, I want it to fit the size of the login button in the background. So I try to scale it using the resize view handlers, and I also have adjusted android:layout_width=… and the height as well. But when I do that the image does not get resized, just the area it is placed in get's resized. This is what happens
As you can see, it just kind of deletes some parts of the image and adjusts the area the image is in. How can I adjust the actual size of the IMAGE part of the button? This is what I have done in .xml
<ImageButton
android:id="#+id/signinButtonLogin"
android:layout_width="115dp"
android:layout_height="53dp"
android:background="null"
app:srcCompat="#drawable/loginbutton"
tools:layout_editor_absoluteX="13dp"
tools:layout_editor_absoluteY="447dp" />
Sorry if this is a basic question, I am just starting to learn my way around .xml

Android how to place a button in correct place on a back ground image to support all screen sizes

I've a button on top of a back ground image in Relative Layout. The image itself contains the 'Register' button shaped image , So now I've placed a android button on the portion where exactly the Text "Register" is there . But my android button is going in different positions based on screens size. Please suggest me how do I place the android button on the required portion of
Put that button to a new relative layout under the your relative layout. And add
android:layout_centerHorizontal="true"
property to new relative layout. So now button always be at the center.
EDIT:
Use this:
<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="#drawable/home1"
>
<Button
android:id="#+id/button1"
android:layout_width="195dp"
android:layout_height="95dp"
android:layout_marginBottom="194dp"
android:layout_centerHorizontal="true"
android:text="button_play" />
</RelativeLayout>
Do you mean to say the image itself contains text "Register"?
There's no easy way you can do it that way in Android.
Problem is Android has different screen sizes and screen densities. So your image itself will start looking blurred and the text in the image may get pixelated making it look ugly on some devices.
So what's the right way then? Use a simple background and place your button and text using ImageButton and TextView or just Button with proper background to it.
Developing for Android is not pixel-perfect as it is/can be for iOS, so this kind of task is kinda tricky. You basically shouldn't have one piece of a button (text in this case) divided from another (button's container).
But if you don't have a choice, I would suggest you to:
Open some photo-editor and get actual positions of your "Register" text on the background image. You will get four X,Y positions for left bottom, left top, right top, right bottom.
Get height and width of your background (or JUST height and width of the device if the background covers all space - match_parent).
You will then have to measure the ratio, so you will know where those points are on a display.
Add a button at "Register" text location.
EDITED
Actually instead of adding a button you can just add a click listener to your background image and intercept user's clicks. If a click was inside of a boundaries (our rectangle shape of XY points) then re-direct user/do something.
Sounds like a lot of work but as I think about it, this is the only way to be absolutely sure you will have a button at exact place you want.
Good luck!

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!

is it possible to specify android:minHeight to be the same as android:layout_width

I have an xml layout file for a venue details page, which specifies a few linear layouts and then a map view. Each linear layout has 2 TextViews, one as a header and another as the detail. At the bottom of the page is a mapView which shows the location of the venue.
On a large screen/tablet the map has plenty of room and looks fine, on a smaller screen, e.g. on a phone the map is squeezed into this tiny space at the bottom of the screen.
I'm happy with main layout of the page except for the map at the bottom.
What I would like to do is to specify that the minimum height of the map is at least the same dp as the available width - i.e. make sure its square. If there is more space for the map to fill at the bottom of the screen - i.e. to make it a portrait aspect rectangle, then it should do so.
Edit : I don't want to reduce the already dynamic size of the LinearLayouts as the information they provide is actually what the user will want to see.
pseudo code below:
<com.google.android.gms.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:minHeight="android:layout_width"
/>
I can see that it would be possible to do this through Java code. I can also see that I would be able to set a specific size such as 320dp, but this then requires more effort to get the size correct for multiple screen sizes.
Is this possible in xml alone?
Having had time to think about the comments made by #confused_at_times, I decided that in fact the problem was in the layout of my activity and not in the unavailable option in the xml.
My chosen solution is to have the map as the main element of the page with the marker pin being clickable and showing all available detail upon click.
It is not possible in XML for most View types.
As you know it can be accomplished in code, but I have always thought this type of a feature would be very helpful.
However for an ImageView you can accomplish something like this using the adjustViewBounds property, for example if you want a banner image at the top of your screen, and you want it to size correctly.
This XML below shows how to use that property:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="#drawable/big_image" />
First impression is that this image will match_parent in both height & width i.e. fill the screen. The scaleType will allow it to change size if required.
The trick is using adjustViewBounds set to true.
The image is scaled, but the bottom bound of the view is brought up to wrap_content of the newly scaled image.
Bear in mind that this method will not stretch a smaller image, but will work when shrinking a larger image onto a smaller screen.

ActionBar bottom align tab icons

i want to bottom align the tab icons but I have no clue how to achieve it :( I have already tried setCustomView without success. Although my custom layout has width and height set to match_parent it doesn't fill the whole tab and therefore i cannot bottom align my content.
Here are two images to illustrate what
i want to achieve
and what i actually get
Here is the custom tab view layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f00">
<ImageView
android:id="#+id/icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"/>
</LinearLayout>
I have added the red background for debugging. And it really is only shown around the icon, and not the entire tab.
The 9-patch image of the tab background is:
So the fill area should be the whole image...
If I'm not wrong, you are using some 9patch image (probably generated using the ABS theme generator). The 9 patch image will determine where the region will be drawn and by default added some padding to it.
To know more about the 9 patch and how to deal with the "drawable region", please take a look of this website
Edit
Just in case you are too lazy to read the article in the link, a 9patch image will not only make a scalable background image, it will also able to determine the "Fill Area" of the content of its children. If the Fill Area is designed to be smaller than the whole image itself, padding will be added to fill the rest and hence producing what you see on the tab now.

Categories

Resources