i try to use nine patch for a layout's background. However, some indicators in the nine patch is displayed. See this link-> http://dl.dropbox.com/u/78582670/NinePatchError.png
How do i remove the indicators??
my nested layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFEFEFE"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/test1" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/menu_bg2">
</FrameLayout>
Thanks you.
Have you looked at the nine patch image itself? You should be able to open it with any graphics editing application. My feeling is that the 9 patch image is actually the problem here and not your layout. To fix this, should you confirm the image contains the errors, just rerun the slicing in the 9patch tool.
Your issue is that you didn't make the 9 patch in the 9 patch tool.
You have two black lines on the left for some reason when you should have one continuous black line on the left and another continuous black line on the top.
Also, I'm not really sure why you'd be using this particular image as a 9 patch. It makes no sense.
http://developer.android.com/tools/help/draw9patch.html This document explains what 9 patches are for and how to set them up correctly.
Related
I have got a very tiny image:
(image made on gimp, it would be invisible if I pasted it here)
It's 5x5px in size and it has some pixels with 100% transparency and others with 80%.
I'm trying to use it as a background for an ImageView. I want to scale it to higher dimensions. However, when I do that, the overall effect becomes blurry and not what I truly want.
XML Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
<ImageView
android:layout_width="500dp"
android:layout_height="500dp"
android:background="#drawable/boxes"/>
</RelativeLayout>
Unwanted result
Question
How do I make it look good? That is, with sharp corner squares.
Investigate using an SVG for the background - these should appear sharp at all sizes
At first, try to resize it MS paint. If this process fails, take a screenshot of that picture to get a more clear view and then resize it again.
I am trying to make a chat bubble. So I tried to make a 9 patch image, But it's not getting auto stretched.
So here is my 9 patch image ,
Google Drive Link
And here is my XML file of the chat bubble..
<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:background="#drawable/bubblee"
>
<TextView
android:id="#+id/txt_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="300dp"
android:padding="5dp"
android:textColor="#000000"
tools:text="lol" />
</RelativeLayout>
And this is how the current chat bubble looks,
Chat bubble image
I think I never made any 9 patch image before, so the problem is with the 9 patch image, tell me if i made any mistake :(
Thank you :3
You kept already a lot of width for your image so by default it will take that much width.
try to make small image from width and then check it if it works or not
Okay this is probably a newb question but I can't find any solutions on google.
I'm a new android programmer and I made a simple hello world type program. I didn't do any funny configurations in the layout xml file but for some reason on certain devices the screen looks really zoomed in and almost kinda pixelated.
Is there some kind of common reason for this? All I have on my linear layout is an EditText widget, a textview widget, and two button widgets.
My Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10px"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/txtUser"
android:layout_height="wrap_content"
android:layout_width="200px"
android:text="" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Submit"
android:onClick="userSubmit" />
</LinearLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Clear Screen"
android:onClick="clearScreen" />
<TextView
android:id="#+id/txtMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16px"
android:text="Ready\n\n"
/>
</LinearLayout>
It's probably some version of the screen compatibility mode which attempts to make old apps compatible with newer large displays, scaling the UI up as necessary. Scaling causes pixelated look as well.
If you don't specify a targetSdkVersion in your manifest, it defaults to 1, enabling all compatibility modes.
Solution: Specify an actual target SDK version you're developing your app on. Usually it should be the highest one available.
It is because you should use DP dp units instead of Pixels px since DP works with the screen density. Remove things like android:layout_width="200px" and change them to android:layout_width="200dp"
PS: note the following:
Generally you do not want to set dp values, you should do pretty well using wrap_content or match_parent, since the LinearLayout calculate widths and heights for you. Try to resist the temptation of setting fixed values to views, unless is extremely necessary. As an experience Android developer I tell you that cases you wanna set fixed width/height are cases like:
You are downloading images from the Internet and you want the ImageView that will show it to be displayed as a placeholder until the download completes.
You're creating an horizontal gallery and you need to give it a maximum height so it wont surpass the screen.
In resume, complicated stuff like that. If you're starting, try to learn to use wrap_content and match_parent, it will save you a lot of headache later on :)
Am running into something that I have spent hours trying to get working. I have tried searching but what stumbles me is how to search a resolution for this as it is a strange and apparently not-so-common issue?
All I want is to be able to stretch a 'dash of paint' vertically using the y-axis scalable area marked as a single pixel on the left. My 9patch file is below:
I have gotten this to HALF-work as can be seen (ignore the top horizontal line, this is a separate imageview):
As you can see, I am missing what I call the 'Non-scalable end' which is basically the static part of the 9patch file (unmarked on left y-axis scalable area)
The code in the layout is simple:
<ImageView
android:id="#+id/repeater"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/PlayersList"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/PlayersList"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/repeater" />
(file is named repeater.9.png and stored in res/drawable-xhdpi)
Note: For some reason this works exactly as required in the 9-patch tool, but doesn't seem to work in eclipse (earlier screenshot):
Is this the effect you were looking for ?
I have attached images for all drawables let me know if it worked.
You can use http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html
to generate 9 patch images instead of making it form default tools.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_example"
android:scaleType="fitXY"
android:contentDescription="#null"
android:adjustViewBounds="false" />
I have a 9-patch background image for my layout and it works fine when the display resoluton is smaller then the image (800x480px). But when I test it on a device with a bigger resoluton, for example 1280x800px, than the layout is broken. Here are two pictures:
The normal and broken layout
The 9-patch image
Here is the relevant layout-code:
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/chalkboard"
android:gravity="top|center"
android:orientation="vertical" >
All in all, the 9-patch doesn't work when the image scales up. But what's the reason and how can I handle it?
Best regards!
You are stretching the frame as well. Just don't stretch the frames on the side. This should do the work: