Long time lurker, first time poster here!
I'm having a problem specifically on my Kindle Fire where when I insert an image (in this case a header and footer) into a relative layout and set the width to "match_parent" or "fill_parent", there is a white border around the sides.
However when I put an image into a linear layout and set the exact same parameters, it works properly.
It works perfectly on phones and my Samsung tablet, I just can't figure out what's going wrong on the Fire.
I'm hoping someone here has a fix for this problem. I can't find anything about it through google or the StackOverflow search.
Here is the XML code for my header and the relative layout.
<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"
tools:context="*****************.MainActivity"
android:background="#drawable/background_xhdpi">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageHeader"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/header_xhdpi"
android:adjustViewBounds="true"/>
(Example of the problem)
Thanks for your time!
To anyone else having this problem a fellow developer gave me the solution.
Add this to your ImageViews that aren't stretching properly:
android:adjustViewBounds="true"
android:scaleType="fitXY"
Related
So I am trying to import a custom image as the background of an android app however it does not fill in all of the edges. The option I have seen is to set a second layout to be a frame layout and then place an image view within it with additional coding along the lines of android:scaleType="centerCrop". This will not fill the entire screen up for me however, heres a screenshot of what ends up happening -
Heres the xml code being used:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/backgroundImage"
android:background="#drawable/backgroundImgr"
android:scaleType="centerCrop"
/>
</FrameLayout>
Another issue is that different users use different resolutions so the background image has to be able to accommodate them all without being cut off. I'm not sure how to do this.
Set ScaleType fitXY and add android:adjustViewBounds ="true"
Please use android:src="#drawable/ instead background .I hope it will helps you.
Want to make space background to my activity and begin to rotate it slowly, but i stuck with that:
screenshot (http://postimg.org/)
The effect I need need I can get if add in XML file
android:scaleY="2"
android:scaleX="2"
but it will not work, android scale pic down when app start.
Guys, really need your help, I in android for 4 day and have bad english
----ADDED---
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/backgroundd"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
I have not tried this, and I am not sure it is the best solution, but could you set a negative android:layout_marginon the image?
android:layout_margin="-100dp"
See here for more: How to get a view larger than its parent?
Also, posting your full XML could help us know more about how you are setting up the layout.
I am using TextViews to render talk bubbles, which are formed from 9-patch .png images stretched to fit whatever a character says. The same TextView is programmatically reused, resized, and shifted to different places on the screen as the conversation occurs.
Everything looks good except sometimes there is a thin (probably 1 pixel) black line above and below, at the edges of the TextView space (the .png's themselves have a transparent background).
I've been searching online for a week, but found no one with this exact same complaint or any solutions based on anything even vaguely similar.
Any thoughts?
[added by request: .xml and screenshot (suddenly this morning my reputation went up to 11 -- woohoo!)]
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityPreMomGirl"
android:background="#drawable/bg_pre_mom_girl"
android:id="#+id/mom_girl_cb" >
<TextView
android:id="#+id/talk_chat"
android:background="#drawable/talk_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible" />
</FrameLayout>
Why are you using TextView? If you want to show text on some background why not to use ImageView.
In my case it was solved by adding "android:background="#android:color/transparent" to the EditText element
First of all, can I just say, I find laying out android UI's to be a frustrating experience? I used to think the XML layouts were simple and clean and awesome but every time I try to make anything with it I spend hours trying to do the simplest things!
In this particular instance I'm trying to make a simple horizontal bar that contains an image button of fixed size on the right and to the left of it I want an ImageView that takes up the rest of the available width. I see similar constructs all the time in the UI: the search box that appears at the top of the screen when searching, the text area and send button for composing text/googletalk messages, etc.
I've tried both a horizontal linear layout and a relative layout, and I can't get the button to look right in either one. My latest attempt has the following layout code:
It looks like this:
Using the hiearchyviewer indicates that both the imageview and the button have the same height (45px). And it shows the view dimensions and positions to be exactly what I'm looking for. Same height (differing widths of course since the ImageView is much wider). And they butt right up next to each other, centered in the Relative Layout. However the button as drawn on screen is obviously not taking up the full ImageButton view. I'm thinking it's something weird about the android system 9patch drawable used for the ImageButton background. But what do I know? I can't get it to look right no matter what I try.
How did you set up your RelativeLayout? Try to set it up like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:layout_width="wrap_content" android:src="#drawable/icon" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:id="#+id/imgButton"></ImageButton>
<ImageView android:id="#+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:src="#drawable/red_button" android:scaleType="fitXY" android:layout_alignBottom="#+id/imgButton" android:layout_alignTop="#+id/imgButton" android:layout_toLeftOf="#+id/imgButton"></ImageView>
</RelativeLayout>
Hope this helps.
If dimensions are exactly how you are looking for , then in ImageButton and ImageView , use android:scaleType="fitXY" and check.
For simple case , I might use linearlayout with horizontal orientation with two buttons in it with proper weights.
I have a question. I've done in XML ImageView. Unfortunately, the "holds" on the left side of the screen on the phone. I wish this picture could shift to the right place.
I would like to point to the X and Y position of the image shifted to the indicated place.
How do I do this?
Please explain in detail because I am a novice programmer of Java.
Sorry for the mistakes. I'm not saying every day in the English language.
I'd not recommend setting fixed positions for elements as it will make your life only harder for different screen sizes.
Use a RelativeLayout. Here is an example of how your XML could look like.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:layout_alignParentRight="true"/>
</RelativeLayout>
This way the ImageView will always be bound to its parents right side. This is achieved by setting android:layout_alignParentRight="true" on the ImageView.
Hope it helps.