How to add top rounded corners to an ImageView.
I've tried with the following method and it doesn't work.
imgView.setClipToOutline(true);
its better to create drawable file with radius just on top and set as a background.
You can create custom backgroung
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#android:color/darker_gray"/>
<corners android:topRightRadius="10dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="10dp"
android:bottomLeftRadius="0dp"/>
</shape>
set in imageview like this
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:background="#drawable/shape"/>
you can create a drawable for this or use this library for better result
https://github.com/vinc3m1/RoundedImageView
Related
Please I am facing a challenge creating and getting the right angles of a shape in XML using android studio. I want the shape to cut out through the screen, but I am not getting the right angles.
I have already created an oval shape in my drawable folder, and I need the shape to position in the left corner of the screen. Can someone pls help? I have included the code snippet and the picture of the required screen needed. Thanks
<TextView
android:layout_width="300dp"
android:layout_height="200dp"
android:rotationY="14"
android:background="#drawable/ellipse_shape"/>
You can try this:-
custom_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/white" />
<!-- Replace with your dimensions-->
<size
android:width="10dp"
android:height="10dp" />
<corners android:bottomRightRadius="10dp" />
</shape>
it output be like this
And the textView code:-
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_shape"/>
Hope You Helpful!
CompileSdkVersion 26, if it's important. I want to create LinearLayout with rounded corners, and background color.
I created 2 LinearLayouts, one with corners, and one with color, but their shapes do not match my expectations.
Code from activity
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/whitegrey"
android:layout_marginTop="340dp"
android:id="#+id/layout"
android:layout_marginStart="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_border"
android:orientation="vertical"
android:padding="6dp"
android:textColor="#color/black">
...
</LinearLayout>
</LinearLayout>
custom_border.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="8dp" android:right="8dp" android:top="8dp" android:bottom="8dp"/>
<stroke android:width="2dp" android:color="#444444" />
</shape>
Actually, there is rounded border, and behind, there is rectangular layout with target color. I want to fill with target color only what is inside borders.
Is there any way to set the fill color, preferably in custom_border.xml?
Here, what I have at the moment:
Here, what I want to achieve:
View from phone, the letters on the left are cut off:
From the code samples you provide us, it doesn't seem necessary to me to have two LinearLayout. Only the layout with android:background="#drawable/custom_border" is required.
To achieve the expected result, just add the property <solid android:color="#color/whitegrey" /> to your custom_border.xml :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="8dp" android:right="8dp" android:top="8dp" android:bottom="8dp"/>
<stroke android:width="2dp" android:color="#444444" />
<solid android:color="#color/whitegrey" />
</shape>
I wish I was able to help you!
The number 4 circle
As you see in the image there is number '4' in a circle within a text and it has a background color. It works as a reference when you click it opens a link in the browser. Is that something can be done in textview using spannable or any other way?
You can achieve this using Drawable.
Simply create background.xml in Drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#color/colorAccent"/>
</shape>
And apply background in TextView,
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/background"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="14dp"
android:paddingBottom="14dp"
android:text="04"
It will generate the result like this,
I want to add shadow effect to my ImageView, like a transparent from bottom side. Here two images with and without shadow effect. Has any possible ways to make like this? Or is it better to take shadow svg file from the internet and put on the original imageView?
You can put your image in the same space with a gradient image using a RelativeLayot like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/your_image"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/grad"/>
</RelativeLayout>
The "grad" image is this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="270"
android:endColor="#181818"
android:startColor="#00000000 " />
<corners android:radius="5dp" />
</shape>
I'm hoping there is an xml solution to this... I am trying to create a layout that has rounded corners and then filling that layout with an image (tiled, repeat). So basically I have a LinearLayout that has a drawble layered-list assigned to the background. Here is the test layout (xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/rate_buttons"
android:layout_width="100dp"
android:layout_height="50dp"
android:orientation="horizontal"
android:padding="0dp"
android:background="#drawable/test_rounded">
</LinearLayout>
</LinearLayout>
here is the test_rounded drawable xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item ><bitmap android:src="#drawable/my_tiled_image" android:tileMode="repeat"/></item>
<item >
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="3dip" android:color="#B1BCBE" />
<corners android:radius="20dip"/>
</shape>
</item>
</layer-list>
The image is overflowing at the corners of the shape/layout border. I get the following
As you can see the corners are overflowed. I heard about modifying the image part (blue pattern) in code but I have issues with that since I do modify it and animate it along the way. SO, if its at all possible to just fill in the layout with that image, please let me know. Thank you all for your help.
You can do this only programatically. But if you want to do this using xml, you have to add the background image in a layout above the rounded corner layout with the help of Relative layout and set margin. This will not give a perfect solution but will solve your problem.
The first is the XML way
Create an xml file in your respective drawable folder for the round border.
I have namedd it as popupborder.xml.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke android:width="2dp" />
<corners android:radius="15dip" />
</shape>
The main 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:layout_gravity="center"
android:layout_margin="10dp"
android:background="#drawable/popupborder" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp" >
<LinearLayout
android:id="#+id/property_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inner view with Background and margin"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
i recommend you to use an image loader library such as universal image loader, picasso etc. Here is an example code for it:
String url = "file://" + your_file_path
com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(url, ivPicture, options);
You have to add
.displayer(new RoundedBitmapDisplayer(px))
to your Universal Image Loader display options.
Also there is another library (i think this is what you are looking for) https://github.com/vinc3m1/RoundedImageView
You can check this. But in second way you can get "Out of Memory Exception" cause of loading big sized image.
I hope this'll help you.