This question already has answers here:
How to make an ImageView with rounded corners?
(58 answers)
Closed 5 years ago.
Im using Picasso and trying to put image in circle imageview, but the picture is still square. How can i fix it ?
Picasso.with(context).load(resId).resizeDimen(R.dimen.image_size, R.dimen.image_size).into(holder.mImageViewItem);
image_size = 60dp
drawable resource :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FFF"/>
and imageview :
<ImageView
android:id="#+id/picture_imageview_item"
android:layout_marginTop="15dp"
android:layout_marginLeft="25dp"
android:layout_marginBottom="15dp"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#drawable/buttonshape" />
There are different libraries you can use for a circle shaped image. The best one which i came across is
Siyamed
You can make a simple circle with white border and transparent content with shape.
// res/drawable/circle.xml
<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="10dp"
android:color="#android:color/white" />
</shape>
Then make a layerlist drawable and put it as background to your imageview.
// res/drawable/img.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/ic_launcher"/>
<item android:drawable="#drawable/circle"/>
</layer-list>
and put it as background to your imageview.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/img"/>
In place of ic_launcher, you can add your image.
Thanks !!
Related
This question already has answers here:
How do I create a ListView with rounded corners in Android?
(11 answers)
Closed 2 years ago.
I have this View in Kotlin:
<View
android:id="#+id/DotView"
android:layout_width="6.5dp"
android:layout_height="6.5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/colorPrimary"
/>
and I need to round the corners since it is a Dot and I have been investigating and testing how I can do it to round the corners but I just can't find the answer.
How can I solve it?
you have to create a drawable shape xml file and set background property of the view to the drawable file!
res/drawable/circle.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#color/colorPrimary" />
</shape>
res/drawable/rounded.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/colorPrimary"/>
<corners android:radius="5dp" />
</shape>
and set background to view like this :
<View
android:id="#+id/DotView"
android:layout_width="6.5dp"
android:layout_height="6.5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#drawable/rounded"
/>
an Imageview is a wrapped in a linearlayout. the linearlayout has a rounded background. I want the imageView not to overlap the rounded corners of the linearlayout. Cardview does something similar but I don't want all corners radius.
Here's my snippet.
<LinearLayout
android:background="#drawable/bottom_sheet_top_stroke"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.chrisbanes.photoview.PhotoView
android:id="#+id/preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:minHeight="300dp"
android:scaleType="center" />
</LinearLayout>
bottom_sheet_top_stroke
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="0dp"
android:left="-6dp"
android:right="-6dp"
android:bottom="-32dp">
<shape android:shape="rectangle">
<solid android:color="#color/dark"/>
<stroke
android:width="5dp"
android:color="#color/white"/>
<corners android:radius="40dp"/>
</shape>
</item>
</layer-list>
how do I achieve making sure the image is within the defined radius of the parent and not overlap.
You have to make your Image with roundedCorners.
For Image loading libaries like Glide and picasso there is already lots of transformation available .
You have to use RoundedCornersTransformation
Glide.with(this).load(url)
.apply(RequestOptions.bitmapTransform(
new RoundedCornersTransformation(this, 10, 10))).into(mImageView);
For transformations you can take reference from glide-transformations .
I want to create buttons in my android application, just like shown in the image below
you can se all the four buttons below.
I want to give them a custom color background and then an icon on the top. There is no way I'm able to adjust the icon at the centre of button.
How can I achieve the desired effect?
You can do this with FrameLayout and for circle background you need to create a shape drawable file. Refer my answer here.
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_shape"
android:clickable="true"
android:focusable="true"
android:visibility="visible"
android:foreground="?android:attr/selectableItemBackground"
android:padding="4dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_star_border_black_24dp"/>
</FrameLayout>
round_shape.xml add this file in drawable folder
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:angle="270"
android:startColor="#color/profile_grey"
android:endColor="#color/profile_grey"/>
</shape>
Create Drawable and use that drawable as Button Background.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:color="#e1e1e1"
android:width="0.5dp"/>
<solid android:color="#android:color/white"/>
</shape>
</item>
</selector>
This Code create a circle with white background.
I am trying to set a backgroundimage to my ImageButton. The ImageButton should be full filled. Currently it looks like:
ImageButton
<ImageButton
android:id="#+id/imgBtn_OpenUserPicture"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_horizontal|center_vertical"
android:src="#drawable/ic_camera"
android:background="#drawable/round_imagebutton"
android:scaleType="centerCrop"
android:tint="#android:color/transparent"
android:padding="20dp"/>
#drawable/round_imagebutton
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/transparent"/>
<corners android:radius="90dp" />
<stroke
android:width="2dp"
android:color="#FFF"
/>
</shape>
</item>
</selector>
One problem could be the padding of 20dp. After removing it, the problem was the same. I think I have to set the image as the background of the shape. But how can I set the image dynamically - captured by the camera - to the shape background?
Use scale type as fit center.
android:scaleType="fitCenter"
There are Two way
1# Use rounded image instead of rectangle to set src
2# use this link instead of ImageButton
https://github.com/hdodenhof/CircleImageView
This question already has answers here:
Android - border for button
(11 answers)
Closed 2 years ago.
Hi I'm covering my ImageView in buttons but while they are so close to each other you cant make out that it is buttons, its just a big red square. I need a quick and easy way to give my buttons borders/edges or something so you can see the different buttons.
Create a Shape in Drawable Resource
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#C0213A" />`<!--Background Color-->`
<stroke android:width="2dip" android:color="#C0213A"/> `<!--Border-->`
</shape>
In your XML
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:background="#drawable/your_shape"> `<!--This is your shape created--`>
There is no border for buttons but you can use shape to make a drawable with border then put it as background for the button.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/red" />
<stroke
android:width="1dp"
android:color="#color/black" />
</shape>