I've been trying to create a frame around my imageview using a picture of a wooden frame. I turned the woodenframe picture into a 9patch and its still not wrapping around the imageview.
<RelativeLayout
android:id="#+id/ChosenPic"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="3"
android:orientation="vertical"
android:padding="10dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:baselineAlignBottom="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/ImageView02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical|fill_horizontal"
android:scaleType="fitXY"
android:src="#drawable/woodenframe" >
</ImageView>
</RelativeLayout>
So this is the ninepatch and i want it to fit around a picture of my choosing no matter the size.
EDIT:
This is what i want.
You have two options. I recommended the first one.
First option:
Put each image view in a separate LinearLayout and apply the 9patch to the LinearLayout it self not the image view
Second option:
Use or set the background resource of the image view in Java to the 9patch resource or the background attr in xml to the 9 patch resource and the src to the image it self.
Note that it better to use a Layer-List and add a combination of two shapes or whatever rather than using a 9patch resource.
Reference:
https://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList
The "nine-patch" frame image that you upload is not a proper nine-patch.
First, it is a jpg. The extension should be .9.png.
Second, the contents are not correct. Specifically:
You need to have a 1px transparent border around the entire image. I do not see that in your jpg, though that just be an artifact of exporting it as a jpg.
You need to define a stretchable region by drawing black pixels in that 1px border. I see no black pixels defining such a region in the uploaded image.
I highly recommend going back and reading the nine-patch documentation again, and trying the draw 9-patch tool for creating a proper nine-patch.
Your 9-Patch is not configured correctly.
It isn't enough to just rename your file. To get it working properly, you have to define certain areas that should be stretched to fit the dimensions of your view.
You can also define paddings for that 9-Patch to inset the content when applying the 9-Patch to your view.
There's a handy tool called "Draw 9-Patch" in the android SDK that helps you defining these areas:
http://developer.android.com/tools/help/draw9patch.html
To start it, simply run the
draw9patch.bat
located in
...\sdk\tools\
Related
I get some images of our new designer but found it strange some of them look like this:
I'm trying to overcome it as it displays well on his device and normal image viewer or PC so while I try I found that if I used src if fit one that has clipped from the right and left (this while using background)
however, if I used src it get fit correctly.
some others (using background)
also, I used src it fits correctly.
I'm confused about this issues and can't find a clarification for it when I googled it.
Code For ImageView
<ImageView
android:id="#+id/aa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/a123"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
Hope anyone can suggest me a way to handle them programmatically and how to persuade designer it is from him if it is?
Hope also someone declares me the core of when using src or background
I don't understand what is your problem exactly.
However,backgroundis for simply defining a shape,color,pattern or anything for our View or Layout.
So you can use this attribute for every layout and button or TextView or anything.
Let's say you have created a Circle.xml file which is a shape.If you call background="#drawable/circle" you can make your ImageView to have a Circular shape.
With src in an ImageView for example you put your Image in the ImageView.
You also can adjust the height and width of the displayed image by layout_width or layout_height which you can set both to "Wrap_content" or "match_parent" or any value
For fitting the image the way you want you should play with layout height and width and layout margin values!
1) I was facing the same issue i fixed it by using android:scaleType="fitXY" it will fit the image accordingly but if you use too small image it will be distorted and if you
will use raw image file make sure to use Compressed image without disturbing the
image quality.
2) All views can take a background image.
The src to an ImageView has additional features:
different scaling types
adjustViewBounds for setting bounds to match image dimensions
some transformations such as alpha-setting
And more that you may find in the docs.Source
I am designing an android app and I need to implement the following interface. I need a round border around this number. For the round border I am using an image with a circle with a gradient border. For the numbers I am using the textview. The problem that I have is that when I debug it, the numbers extremely sharp and clean but the circle is not that sharp. The borders look quite rough. I took a screenshot of it but on the phone the thing is much more evident. I also noticed this when I was using an image and a background. The picture in the background was much more clear than the image on the screen. How can I fix this.
This is the XML that I am using
<ImageView
android:layout_width="270dp"
android:layout_height="270dp"
android:id="#+id/imageView"
android:background="#drawable/b"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
Not sure about that image sharpness but you should consider on below points with your ImageView,
Setting the image to the ImageView using android:src="..." rather than android:background="...". src= makes it scale the image maintaining aspect ratio!
You should also use android:adjustViewBounds="true" to make the ImageView resize itself to fit the resealed image.
You can change the way it default scales images using the android:scaleType parameter, use android:scaleType="centerCrop" and see if it gets more clear.
I'm trying to make a 9-Patch image to use for Android application.
Here is a screenshot from 9-Patch tool with my image:
I'm adding on layout this image:
<Button android:id="#+id/tiny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:text="Text"
android:textSize="8sp"
android:background="#drawable/arrow_active" />
(Image is located in "drawable" folder and image name is "arrow_active.9.png" )
Here is a screenshot from eclipse:
On real device I also don't see the arrow of image.
I'm tried with ImageView and Button, layout is TableRow.
Also I tried with smaller image:
On real device I see black pixels added by 9Path tool.
Try this tool...
It is graphically well, and auto generate images for all buckets. You can set streatch regions and content padding from it..
So I have a PNG as shown below. The white inner in the image is transparent.
My problem is that this image isn't really scalable for different size screens on Android devices.
I would like to know how I can do this either in code or preferably, xml. Basically I am looking for a grey square with a transparent circle inset.
Also, there is a nice effect on the inner border of the grey, is this possible in code?
I know how to do the inverse (bitmap with rounded corners) but how would I do this? Any ideas appreciated, thanks.
Edit:
So, the only thing I have tried is android:scaleType="centerCrop"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:scaleX="0.7"/>
</LinearLayout>
Can you try this one.
It's not clear from your question why the image is not scaling properly for different screen sizes.
Using NinePatch PNG format you have full control how the image scales. For example, this enables you to force that only the image gray areas are extended, keeping the circle format, if that is your problem.
The documentation can be found here: Draw 9-patch
Regards.
I am trying to use the 9-patch technique to create the button.
It looks almost great in the Layout Window of Eclipse
When I run it in the emulator it shows up like this:
Here is the actual PNG image
Selector XML
<item android:drawable="#drawable/splash_facebook_button" />
Button Code in Layout
<Button
android:id="#+id/button1"
android:layout_width="208dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dip"
android:background="#drawable/splash_facebook_button_selector"
android:text="Sign up with Facebook" />
Looks to me like it's not treating the image as a 9-patch. Have you saved it with the .9.png extension?
Edit:
Had a better look at the actual image and I don't think you've quite got it set up correctly. The bottom and right border define where the content will go (in this case you want it over to the right, with a bit of padding).
The top and left define the areas that will be stretched when the image is scaled. In this case you want it to be areas of constant blue that get stretched, rather than the logo. I've updated the image with an example of how to do this:
This works for me!