Skip to content

Instantly share code, notes, and snippets.

@avipars
Created April 6, 2020 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avipars/a6557ae9b16aabee99a3cb3884a985ba to your computer and use it in GitHub Desktop.
Save avipars/a6557ae9b16aabee99a3cb3884a985ba to your computer and use it in GitHub Desktop.
Badge for my app
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
tools:targetApi="m">
<!-- grid items for RecyclerView -->
<ImageView
android:id="@+id/image"
android:layout_width="55dp"
android:layout_height="60dp"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:scaleType="fitXY"
android:paddingBottom="@dimen/image"
android:layout_marginBottom="@dimen/text_padding"
app:srcCompat="@drawable/programmer"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image"
android:textColor="?attr/textColor"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|center"
android:layout_marginTop="@dimen/text_padding"
android:paddingBottom="@dimen/text_padding"
android:text="@string/programmer_activity" />
</RelativeLayout>
@AmosKorir
Copy link

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >

  <ImageView
      android:id="@+id/imageView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:srcCompat="@drawable/ic_launcher_background"
      />
  <TextView
      android:id="@+id/badge"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:visibility="invisible"
      android:text="badge"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      />
  <TextView
      android:id="@+id/name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="8dp"
      android:text="name"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/imageView"
      />
</androidx.constraintlayout.widget.ConstraintLayout>

@avipars
Copy link
Author

avipars commented Apr 6, 2020



<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/image"
    android:textColor="?attr/textColor"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom|center"
    android:layout_marginTop="@dimen/text_padding"
    android:paddingBottom="@dimen/text_padding"
    android:text="@string/programmer_activity" />

<TextView
    android:rotation="25"
    android:id="@+id/badge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:padding="10dp"
    android:text=""
    android:textSize="12dp"
    android:textColor="?attr/textColor" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment