Why is it so difficult to make this little thing work? : /
I want to create something like android's lock screen.
I have an XML:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke
android:width="#dimen/dp_5"
android:color="#color/black" />
<gradient
android:type="radial"
android:startColor="#color/green"
android:endColor="#color/red"
android:gradientRadius="#dimen/dp_50" />
</shape>
This circle is a background of a TextView, so the following happens:
1. wrap_content creates a little circle in the center of the screen
2. fill_parent creates an elipse taking the whole screen, instead of a circle
In addition I would like to change the startColor and endColor programmatically - Didn't find any documentations\threads which solved this SIMPLE issue.
Related
So I have a background texture (image) that I put on all of my buttons. I want to create a circular button with an icon that retains this background texture.
So far, I have noticed it isn't supported to do this on the shape side:
<shape android:shape="rectangle">
<solid android:color="#drawable/myTexture" /> <!-- this isn't supported -->
</shape>
Lastly I would otherwise try to use <layer-list>, however as I stated above, I need to still crop the texture to my shape I'm creating.
Is the only way to do this to make my own circular images that combine the background texture and the button icon? This seems a bit excessive, as I would think there should be a programmatic way to accomplish this, but I could be wrong.
Here is an example of what I mean above:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/myTexture" />
<item>
<shape android:shape="rectangle">
<corners android:radius="40dp" />
<size
android:height="80dp"
android:width="80dp" />
<solid android:color="#color/black" />
</shape>
</item>
</layer-list>
In the picture bellow: black is the circle shape, silver is the texture/image (black for contrast)
I haven't solved the programmatic way, but I did end up creating new graphics that combined the icon and the background texture. Using this singular image, I was able to create circular ImageButton's.
I am trying to get a gradient inside a rectangle to look like this
The closest I get using following xml is
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="radial"
android:startColor="#color/lightPurple"
android:endColor="#color/lightGreen"
android:gradientRadius="600"
android:angle="270"
android:centerX="1"
android:centerY="0"/>
</shape>
Is there anything I can do to make my gradient go from the top right corner to bottom left corner?
Try android:type='linear' and android:angle='45'.
This would get you more closer to edge-to-edge. Android doesn't provide arbitrary angles for this. The only valid angles are the ones which are a multiple of 45. However as far as I can see, the gradient you require is not actually edge-to-edge and I suspect it to be the one with angle 45.
What is the best way to implement the below graphics in android?
For the image view I am using
de.hdodenhof.circleimageview.CircleImageView
I need to have a button over the bottom 1/3 of the image view and match the curve. Is there a way similar to iOS where I can place the two in a layout and then just set the curve of the layout and clip to bounds? Or what is the best way to solve this? I do have an xml file for the button and I can get a match if I cover half the image, but have not been able to figure out less than that. Here is my button shape:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size
android:width="10dp"
android:height="5dp"/>
<corners
android:bottomLeftRadius="1000dp"
android:topLeftRadius="0dp"
android:bottomRightRadius="1000dp"
android:topRightRadius="0dp" />
<solid android:color="#color/transparent_lightGray" />
</shape>
I want to create a single pixel stroke rectangle, but android is rendering two pixels.
Here is my xml code:
<item>
<shape android:shape="rectangle">
<solid android:color="#FFF" />
<stroke android:width="1px" android:color="#000" />
</shape>
</item>
Here is the top left corner of what is rendered:
My only guess is that this background is not lining up with the device pixels.
So, essentially a line? You could try using something like
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<solid android:color="#FFF" />
<stroke android:width="1px" android:color="#000"/>
</shape>
EDIT: whoops, think I misunderstood. You could always just draw a rectangle using lines though I guess.
px has different meanings on different screen sizes. I'm guessing this is on a bigger screen? Try changing the unit to dp and the anti-aliasing affect should disappear
edit: actually this wont solve your issue if you just want the physical thickness of the line on your screen to be half its current size. It will make it look equivalent on all types of screen though and keep a solid appearance, if that's your complaint
This was caused by the bi-linear filtration introduced in honeycomb and later. There are two solutions:
Disable all hardware acceleration in the manifest (bad idea) with this tag
android:hardwareAccelerated="false"
Use the xml attribute on affected views to render with software only
android:layerType="software"
I found the solution here:
Blurred 1dip shape lines (borders) on Android
I have a screen with a label on top. This label is done with a TextView.
As a background I'd like to have a vertical gradient, starting with color1, changing to color2 and back to color1.
At the moment I have:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1px" android:color="#000000" />
<gradient
android:startColor="#FFFFFFFF"
android:centerColor="#FF8800"
android:endColor="#FFFFFFFF"
android:type="linear"
android:angle="270"
/>
<corners android:radius="10dp"/>
</shape>
My problem is that the centerColor line is too thin. I want it to ocupy all the letters space.
I can't find any way to make the gradient to be faster.
I've already tried to use a layout-list but with no success.
Any idea?
This is a much more different track to follow but have you considered working with 9-patch image files? This will allow you to stretch the parts of the gradient that you wish to and make the centre line as big as needed by segmenting up the background properly.
Here are some great tutorials I have used to learn about them:
draw 9 patch tutorial
And from Google's own Android mouth:
Android 9 patch
All Drawable resources for Android