banner



How To Add A Circle Background To A Image Android

Shape your Image: Circle, Rounded Square, or Cuts at the corner in Android

Source Lawmaking link at lesser of this page.

Step 1

            implementation 'com.google.android.textile:material:one.6.0'          

Pace 2

            <?xml version="1.0" encoding="utf-viii"?>
<resources>

<style proper name="Circular">
<item name="cornerSize">l%</item>
</mode>

<style proper name="RoundedSquare">
<detail name="cornerSize">x%</item>
</way>

<style name="CornerCut">
<item name="cornerSize">15dp</detail>
<item name="cornerFamily">cutting</particular>
</mode>

<mode name="DiamondCut">
<detail name="cornerSize">75dp</item>
<item name="cornerFamily">cut</item>
</style>

<style proper name="SpecificCornerCut">
<item proper name="cornerSizeTopRight">75dp</item>
<item name="cornerFamilyTopRight">cut</particular>
<item name="cornerSizeBottomLeft">75dp</item>
<item name="cornerFamilyBottomLeft">cut</item>
</style>

<style name="SpecificCornerRounded">
<item proper noun="cornerSizeTopRight">75dp</particular>
<item name="cornerFamilyTopRight">rounded</item>
<item name="cornerSizeBottomLeft">75dp</detail>
<item proper noun="cornerFamilyBottomLeft">rounded</item>
</style>

</resource>

  • Each <way> represents a new shape. The 'name' of the <fashion> is user-defined.
  • <style> can contain multiple <item> tags.
  • <item> contains 'proper noun' attribute to define the corner shapes. Such equally 'cornerSize', 'cornerFamily', 'cornerSizeTopRight' etc are the pre-defined values of the attribute 'name'.
  • cornerSize: This value defines the corner shape. You tin can use accented % or a value in dp. Increasing the % or the dp value will increase the masked expanse of your epitome. Below is the instance:

  • cornerFamily: This value defines the corner shape blazon. It can be either rounded or cut. Using rounded will make the corner curved whereas using cutting will give the corner a subtle cut. If you lot don't declare cornerFamily, and so past default it volition exist rounded. Below is the instance:

Step 3

He was my childhood favourite (earlier he got divorced and disappeared)

Step four

            <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/txvCircularShape"
style="@style/TextAppearance.AppCompat.Championship"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:background="#eee"
android:gravity="center"
android:text="Round ImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imvCircular"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:src="@drawable/action_hero"
app:layout_constraintEnd_toStartOf="@+id/imvCircularWithStroke"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/txvCircularShape"
app:shapeAppearanceOverlay="@fashion/Circular"/>

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imvCircularWithStroke"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:padding="5dp"
android:src="@drawable/action_hero"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/imvCircular"
app:layout_constraintTop_toBottomOf="@id/txvCircularShape"
app:shapeAppearanceOverlay="@style/Circular"
app:strokeColor="#00BCD4"
app:strokeWidth="5dp" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/textCornerRadiusShare"
style="@manner/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:groundwork="#eee"
android:gravity="eye"
android:text="Corner Radius ImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imvCircularWithStroke" />

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imvCornerStroke"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:src="@drawable/action_hero"
app:layout_constraintEnd_toStartOf="@+id/imvCornerRadiusWithStroke"
app:layout_constraintHorizontal_bias="0.v"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textCornerRadiusShare"
app:shapeAppearanceOverlay="@fashion/RoundedSquare" />

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imvCornerRadiusWithStroke"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:padding="5dp"
android:src="@drawable/action_hero"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.v"
app:layout_constraintStart_toEndOf="@+id/imvCornerStroke"
app:layout_constraintTop_toBottomOf="@id/textCornerRadiusShare"

app:shapeAppearanceOverlay="@mode/RoundedSquare"
app:strokeColor="#00BCD4"
app:strokeWidth="5dp" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/txvCornerCut"
fashion="@style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:background="#eee"
android:gravity="heart"
android:text="Corner Cut ImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imvCornerRadiusWithStroke" />

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imvCornerCutOne"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:src="@drawable/action_hero"
app:layout_constraintEnd_toStartOf="@+id/imvCornerRadiusWithStroke"
app:layout_constraintHorizontal_bias="0.five"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/txvCornerCut"
app:shapeAppearanceOverlay="@fashion/CornerCut" />

<com.google.android.fabric.imageview.ShapeableImageView
android:id="@+id/imvCornerCutTwo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:padding="7dp"
android:src="@drawable/action_hero"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/imvCornerStroke"
app:layout_constraintTop_toBottomOf="@id/txvCornerCut"
app:shapeAppearanceOverlay="@mode/DiamondCut" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/txvCornerShape"
style="@manner/TextAppearance.AppCompat.Championship"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:background="#eee"
android:gravity="center"
android:text="Specified Corner Radius ImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imvCornerCutTwo" />

<com.google.android.cloth.imageview.ShapeableImageView
android:id="@+id/imvCornerShapeOne"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:src="@drawable/action_hero"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/imvCornerRadiusWithStroke"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/txvCornerShape"
app:shapeAppearanceOverlay="@style/SpecificCornerCut" />

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imvCornerShapeTwo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:padding="7dp"
android:src="@drawable/action_hero"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.five"
app:layout_constraintStart_toEndOf="@+id/imvCornerStroke"
app:layout_constraintTop_toBottomOf="@id/txvCornerShape"
app:shapeAppearanceOverlay="@style/SpecificCornerRounded" />

</androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

  • Instead of plain <ImageView>, I am using <ShapeableImageView> which is a modern grade of MDC library.
  • Use app:shapeAppearanceOverlay aspect and refer to different <style> created in Stride 2.
  • Additionally, yous tin can use app:strokeColor and app:strokeWidth to employ an outline stroke to your image.

Terminal Event

How To Add A Circle Background To A Image Android,

Source: https://medium.com/smartherd/shape-your-image-circle-rounded-square-or-cuts-at-the-corner-of-image-in-android-cf92f38c217f

Posted by: becerrawituare.blogspot.com

0 Response to "How To Add A Circle Background To A Image Android"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel