LabelView


Source link: https://github.com/linger1216/labelview

LabelView


Sometimes, we need to show a label above an ImageView or any other views. Well, LabelXXView will be able to help you. It's easy to implement as well!

Import your project

Gradle

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {

...
maven {
 url "https://jitpack.io" 
}
  
}
 
}
 

Step 2. Add the dependency

dependencies {
  compile 'com.github.linger1216:labelview:v1.1.2' 
}
 

Or Manual

Copy all java files and attr.xml into your project.


Create a Label

put xml code in you layout, like follows.

LabelButtonView

<com.lid.lib.LabelButtonView
  android:id="@+id/labelbutton"
  android:layout_width="200dp"
  android:layout_height="48dp"
  android:background="#03a9f4"
  android:gravity="center"
  android:text="Button"
  android:textColor="#ffffff"
  app:label_backgroundColor="#C2185B"
  app:label_distance="20dp"
  app:label_height="20dp"
  app:label_orientation="RIGHT_TOP"
  app:label_text="HD"
  app:label_textSize="12sp" />

LabelImageView

<com.lid.lib.LabelImageView
  android:id="@+id/image1"
  android:layout_width="0dp"
  android:layout_height="match_parent"
  android:layout_weight="1"
  android:scaleType="centerCrop"
  android:src="@mipmap/image1"
  app:label_backgroundColor="#C2185B"
  app:label_orientation="LEFT_TOP"
  app:label_text="CHINA" /> 

LabelTextView

<com.lid.lib.LabelTextView
  android:id="@+id/text"
  android:layout_width="wrap_content"
  android:layout_height="48dp"
  android:layout_gravity="center"
  android:layout_marginTop="8dp"
  android:background="#212121"
  android:gravity="center"
  android:padding="16dp"
  android:text="TextView"
  android:textColor="#ffffff"
  app:label_backgroundColor="#03A9F4"
  app:label_distance="15dp"
  app:label_orientation="LEFT_TOP"
  app:label_text="POP"
  app:label_textSize="10sp" /> 

Parameter Description

If you need Label in your custom View

  1. create an new view class extends YourView
  2. use LabelViewHelper as your Member objects
  3. In Constructor function and onDraw function call LabelViewHelper method.
  4. Call the LabelViewHelper method in other functions

like as follows:

public class LabelXXXView extends YourView {

  LabelViewHelper utils;
  public LabelXXXView(Context context) {

this(context, null);

  
}

  public LabelXXXView(Context context, AttributeSet attrs) {

this(context, attrs, 0);

  
}

  public LabelXXXView(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

utils = new LabelViewHelper(context, attrs, defStyleAttr);

  
}

  @Override
  protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

utils.onDraw(canvas, getMeasuredWidth(), getMeasuredHeight());

  
}

  public void setLabelHeight(int height) {

utils.setLabelHeight(this, height);

  
}

  public int getLabelHeight() {

return utils.getLabelHeight();

  
}

  public void setLabelDistance(int distance) {

utils.setLabelDistance(this, distance);

  
}

  public int getLabelDistance() {

return utils.getLabelDistance();

  
}

  public boolean isLabelVisual() {

return utils.isLabelVisual();

  
}

  public void setLabelVisual(boolean enable) {

utils.setLabelVisual(this, enable);

  
}

  public int getLabelOrientation() {

return utils.getLabelOrientation();

  
}

  public void setLabelOrientation(int orientation) {

  utils.setLabelOrientation(this, orientation);

  
}

  public int getLabelTextColor() {

return utils.getLabelTextColor();

  
}

  public void setLabelTextColor(int textColor) {

utils.setLabelTextColor(this, textColor);

  
}

  public int getLabelBackgroundColor() {

return utils.getLabelBackgroundColor();

  
}

  public void setLabelBackgroundColor(int backgroundColor) {

  utils.setLabelBackgroundColor(this, backgroundColor);

  
}

  public String getLabelText() {

return utils.getLabelText();

  
}

  public void setLabelText(String text) {

utils.setLabelText(this, text);

  
}

  public int getLabelTextSize() {

return utils.getLabelTextSize();

  
}

  public void setLabelTextSize(int textSize) {

utils.setLabelTextSize(this, textSize);

  
}
 
}

Thanks

License

Copyright 2014 linger1216  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Versatile map area / geofence utility for google maps v2 for android. Create geofence areas in your map by initializing MarkerBuilderManager.

Android Library demonstrating a material intro tutorial much like the ones on Google Sheets

This library creates an introduction screen for your application. The help tutorial takes the background colour set for each page and when scrolling between the two pages, the two colours will fade into one another.

A simple but powerful Tween / SpriteSheet / ParabolicMotion / animation library for Android TextureView and SurfaceView.

This library has been built in order to provide a Reactive wrapper around the Android Network Service Discovery API and the JmDNS implementation for older devices.

A tiny Android library that makes a very simple horizontal ProgressBar with animation.

Android custom button with centered drawable.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes