開(kāi)源電商app常用標(biāo)簽"hot"之第三方開(kāi)源LabelView
先給大家展示下效果圖,看看是不是在你的意料之中哈。

LabelView是在github上一個(gè)開(kāi)源的標(biāo)簽庫(kù)。其項(xiàng)目主頁(yè)是:https://github.com/linger1216//labelview
LabelView為一個(gè)TextView,ImageView或者為L(zhǎng)istView中適配器getView返回的View,增加一個(gè)左上角或者右上角的標(biāo)簽
這種需求設(shè)計(jì)在商城類APP、電商類APP中比較常用,這些APP展示的商品,通常會(huì)增加一些促銷或者該類商品的特征。
LabelView集成自Android TextView,可以像使用Android TextView一樣使用LabelView,LabelView使用簡(jiǎn)單,如代碼所示:
布局代碼:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.zzw.textlabelview.MainActivity" >
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:background="#CAF"
android:gravity="center"
android:text="textView"
android:textSize="sp" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:background="#FADA"
android:gravity="center"
android:text="textView"
android:textSize="sp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=""
android:background="#BDDB"
android:src="@drawable/ic_launcher" />
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="dip"
android:background="#eee" >
</View>
</LinearLayout>
JAVA代碼:
package com.zzw.textlabelview;
import com.lid.lib.LabelView;
import com.lid.lib.LabelView.Gravity;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//為TextView左上角添加一個(gè)標(biāo)簽
LabelView label = new LabelView(this);
label.setText("Hot");
label.setBackgroundColor(xffaf);
label.setTargetView(findViewById(R.id.textView), , Gravity.LEFT_TOP);
//為TextView右上角添加一個(gè)標(biāo)簽,點(diǎn)擊標(biāo)簽移除
final LabelView label = new LabelView(this);
label.setText("點(diǎn)擊移除");
label.setBackgroundColor(xffEE);
label.setTargetView(findViewById(R.id.textView), ,
Gravity.RIGHT_TOP);
findViewById(R.id.textView).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
label.remove();
Toast.makeText(getApplicationContext(), "標(biāo)簽移除成功", ).show();
}
});
//為ImageView添加一個(gè)左上角標(biāo)簽,并且自定義標(biāo)簽字顏色
LabelView label = new LabelView(this);
label.setText("推薦");
label.setTextColor(Color.RED);
label.setBackgroundColor(xffaf);
label.setTargetView(findViewById(R.id.imageView), ,
Gravity.LEFT_TOP);
//為IamgeView添加一個(gè)右上角標(biāo)簽
LabelView label = new LabelView(this);
label.setText("推薦");
label.setBackgroundColor(xffEE);
label.setTargetView(findViewById(R.id.imageView), ,
Gravity.RIGHT_TOP);
//為一個(gè)View添加一個(gè)左上角標(biāo)簽(ListView用)
LabelView label = new LabelView(this);
label.setText("view");
label.setTextColor(Color.BLUE);
label.setBackgroundColor(xffEE);
label.setTargetView(findViewById(R.id.view), , Gravity.LEFT_TOP);
}
}
以上內(nèi)容是本文給大家分享的開(kāi)源電商app常用標(biāo)簽"hot"之第三方開(kāi)源LabelView,希望大家喜歡。
相關(guān)文章
實(shí)例詳解用戶輸入 i. 檢測(cè)常用手勢(shì)
通過(guò)本段代碼給大家介紹當(dāng)用戶輸入i檢測(cè)常用手勢(shì)的相關(guān)內(nèi)容,代碼簡(jiǎn)單易懂,感興趣的朋友一起學(xué)習(xí)吧2016-01-01
Android開(kāi)發(fā)實(shí)現(xiàn)圖片圓角的方法
這篇文章主要介紹了Android開(kāi)發(fā)實(shí)現(xiàn)圖片圓角的方法,涉及Android針對(duì)圖形圖像的相關(guān)操作技巧,需要的朋友可以參考下2016-10-10
android基本控件ToggleButton&Switch使用指南
本文給大家匯總介紹了android的2個(gè)基本控件ToggleButton和Switch的使用方法,非常的詳細(xì),有需要的小伙伴可以參考下。2016-01-01
Android開(kāi)發(fā)listview選中高亮簡(jiǎn)單實(shí)現(xiàn)代碼分享
這篇文章主要介紹了Android開(kāi)發(fā)listview選中高亮簡(jiǎn)單實(shí)現(xiàn)代碼分享,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01
Android獲取清單文件中的meta-data,解決碰到數(shù)值為null的問(wèn)題
這篇文章主要介紹了Android獲取清單文件中的meta-data,解決碰到數(shù)值為null的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03
Android studio將Module打包成Jar的方法
這篇文章主要介紹了Android studio將Module打包成Jar的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-10-10
Android藍(lán)牙通信之搜索藍(lán)牙設(shè)備
這篇文章主要介紹了Android藍(lán)牙通信之搜索藍(lán)牙設(shè)備,需要的朋友可以參考下2017-09-09
kotlin中object關(guān)鍵字的三種使用場(chǎng)景
這篇文章主要給大家介紹了關(guān)于kotlin中object關(guān)鍵字的三種使用場(chǎng)景,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用kotlin具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06

