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>
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 have a problem with an ImageView, I would like to put this image in a circle that contains only a border with the transparent inside so that the image takes up all the space, but without leaving the circle.
What is currently not working! The image goes beyond the circle and I'd like to fix it! Do you have any idea?
This is my circle :
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="6dp"
android:color="#color/colorRedLogoDark"/>
<corners android:radius="1000dp"/>
This is my ImageView :
<ImageView
android:id="#+id/icon_about"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:src="#drawable/thermometer"
android:background="#drawable/background_about"
/>
It's possible or I have to got a round image ?
EDIT : Actually, I would like to got an image with a border-radius in color !
There are several approaches to tackle this.
1- You can wrap your image in a card view and adjust the corners to look like a circle. The padding in that case will act as a border
To achieve a circular shape using Card view you can set the shape property, android:shape="ring".
app:cardCornerRadius should be set to half the width or height of the ImageView
2- Use a library that does exactly that such as CircleImageView
3- Crop your image through java
I would like you to modify your background_abtout.xml file and simply add this lines of code
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="1.9"
android:useLevel="false" >
<solid android:color="#android:color/transparent" />
<stroke
android:width="6dp"
android:color="#color/colorRedLogoDark"/>
I think this will work perfectly fine
I know how to give round borders using XML in Android. I thought it would be cool to make the radius of one corner of my textView excessively large. The problem is, the text keep spilling out. Can I make my textview have a TRULY round corner? (Not just the background). If this was CSS this would be so easy. I am new to Android.
So in terms of CSS, I want to set my overflow to hidden so to speak.
Please help me.
In short, no. All Views are rectangular and fit in bounding boxes.
The best way to achieve rounded corners is the way you mention; using a shape drawable with corner radius set as the background to your TextView.
Like ataulm said, all Views are rectangular.
Create a shape drawable allows you to create a background with rounded corners. You'd have to use padding to make sure the text doesn't clip in certain areas.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff"/>
<stroke android:width="4dp"
android:color="#ff0000"/>
<padding android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
how can i make a shadow for round corners? I tried it with views for the bottom, right an the corner, but that works not really :D
I tried this xml for the corner:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#404040"
android:centerColor="#DBDBDB"
android:endColor="#color/shadow_end"
android:angle="315"
>
</gradient>
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"/>
</shape>
Is it good to use views for shadows? What you are using?
Thanks for help :)
You can simply draw a 9-patch image with Photoshop drawing the shadows and put it into the drawable folders and set this in your View in xml:
android:background="#drawable/your_9patch_image"
I always do it by using Photoshop. For more details see this: Draw 9-patch
Or you can check in the default Android Studio drawables and see if there's one that you like. Check my answer here: my answer
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.