Android仿京東分類模塊左側(cè)分類條目效果
更新時(shí)間:2018年02月11日 10:21:13 作者:siyadong1
這篇文章主要為大家詳細(xì)介紹了Android仿京東分類模塊左側(cè)分類條目效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了Android仿京東左側(cè)分類條目效果的具體代碼,供大家參考,具體內(nèi)容如下
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; import android.widget.ScrollView; import android.widget.TextView; import com.frame.R; import java.util.ArrayList; import java.util.List; /** * Created by syd on 2016/10/9. */ public class TestActivity extends Activity { ScrollView sv_test; LinearLayout ll_test_contain; List<String> goodsList = new ArrayList<String>(); List<TextView> textViewList = new ArrayList<>(); List<View> viewList = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_activity_test); initViews(); initData(); } /** * 初始化控件 */ private void initViews() { sv_test = (ScrollView) findViewById(R.id.sv_test); ll_test_contain = (LinearLayout) findViewById(R.id.ll_test_contain); } protected void initData() { goodsList.add("常用分類"); goodsList.add("潮流女裝"); goodsList.add("品牌男裝"); goodsList.add("內(nèi)衣配飾"); goodsList.add("家用電器"); goodsList.add("手機(jī)數(shù)碼"); goodsList.add("電腦辦公"); goodsList.add("個(gè)護(hù)化妝"); goodsList.add("母嬰頻道"); goodsList.add("食物生鮮"); goodsList.add("酒水飲料"); goodsList.add("家居家紡"); goodsList.add("酒水飲料"); goodsList.add("整車車品"); goodsList.add("運(yùn)動(dòng)戶外"); goodsList.add("圖書"); goodsList.add("鐘表"); goodsList.add("居家生活"); goodsList.add("珠寶飾品"); goodsList.add("音像制品"); goodsList.add("家具建材"); goodsList.add("計(jì)生情趣"); goodsList.add("營養(yǎng)保健"); goodsList.add("奢侈禮品"); goodsList.add("生活服務(wù)"); goodsList.add("旅游出行"); //動(dòng)態(tài)生成每一個(gè)條目 for (int i = 0; i <goodsList.size() ; i++) { View view = getLayoutInflater().inflate(R.layout.test_item_scrollview,null); view.setOnClickListener(textOnClickListener); TextView tv_item_scroll = (TextView) view.findViewById(R.id.tv_item_scroll); view.setId(i); tv_item_scroll.setText(goodsList.get(i)); ll_test_contain.addView(view); viewList.add(view); textViewList.add(tv_item_scroll); } changeTextColor(0); } private View.OnClickListener textOnClickListener = new View.OnClickListener() { @Override public void onClick(View v) { changeTextColor(v.getId()); changeTextLocation(v.getId()); } }; //改變點(diǎn)擊條目的位置,居中 private void changeTextLocation(int textPosition) { int x = (viewList.get(textPosition).getTop() - sv_test.getHeight()/2 + (viewList.get(textPosition).getHeight() / 2)); sv_test.smoothScrollTo(0, x); } //改變點(diǎn)擊條目的顏色 private void changeTextColor(int textPosition) { for (int i = 0; i <textViewList.size() ; i++) { textViewList.get(i).setTextColor(0xFF000000); textViewList.get(i).setBackgroundColor(0x00000000); } textViewList.get(textPosition).setTextColor(0xFFFF0000); textViewList.get(textPosition).setBackgroundColor(0xFFFFFFFF); } }
代碼2:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.frame.activity.TestScrollView android:id="@+id/sv_test" android:layout_width="80dp" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/ll_test_contain" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> </LinearLayout> </com.frame.activity.TestScrollView> </LinearLayout>
代碼3:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:gravity="center" android:paddingBottom="16dp" android:paddingTop="16dp" android:id="@+id/tv_item_scroll" android:layout_width="match_parent" android:layout_height="wrap_content" /> <ImageView android:background="#cccccc" android:layout_width="match_parent" android:layout_height="1dp" /> </LinearLayout>
效果圖:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Android RecyclerView實(shí)現(xiàn)點(diǎn)擊條目刪除
- Android自定義SwipeLayout仿QQ側(cè)滑條目
- Android更多條目收縮展開控件ExpandView的示例代碼
- Android ListView自動(dòng)生成列表?xiàng)l目的實(shí)例
- Android XRecyclerView實(shí)現(xiàn)多條目加載
- Android條目拖拽刪除功能實(shí)例代碼
- Android ListView 條目多樣式展示實(shí)例詳解
- android RecyclerView實(shí)現(xiàn)條目Item拖拽排序與滑動(dòng)刪除
- Android中l(wèi)istview和imageview實(shí)現(xiàn)條目單選效果
- Android編程實(shí)現(xiàn)canvas繪制餅狀統(tǒng)計(jì)圖功能示例【自動(dòng)適應(yīng)條目數(shù)量與大小】
- Android中RecyclerView上拉下拉,分割線,多條目的實(shí)例代碼
- Android 中 SwipeLayout一個(gè)展示條目底層菜單的側(cè)滑控件源碼解析
- 詳解Android中實(shí)現(xiàn)ListView左右滑動(dòng)刪除條目的方法
- Android實(shí)現(xiàn)下拉展示條目效果
相關(guān)文章
Android Canvas方法總結(jié)最全面詳解API(小結(jié))
本篇文章主要介紹了Android Canvas方法總結(jié)最全面詳解API(小結(jié)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11關(guān)于android studio通過命令行運(yùn)行g(shù)radle編譯命令的問題
這篇文章主要介紹了關(guān)于android studio通過命令行運(yùn)行g(shù)radle編譯命令的問題,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-11-11解決Android Studio Design界面不顯示layout控件的問題
這篇文章主要介紹了解決Android Studio Design界面不顯示layout控件的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Android源碼中final關(guān)鍵字的用法及final,finally,finalize的區(qū)別
Android的源碼中很多地方對final關(guān)鍵字的用法很是“別出心裁”,之所以這么說是因?yàn)槲覐臎]看過是這么使用final關(guān)鍵字的,通過本文給大家分享Android源碼中final關(guān)鍵字的用法及final,finally,finalize的區(qū)別,感興趣的朋友一起學(xué)習(xí)吧2015-12-12Android App調(diào)試內(nèi)存泄露之Cursor篇
最近在工作中處理了一些內(nèi)存泄露的問題,在這個(gè)過程中我尤其發(fā)現(xiàn)了一些基本的問題反而忽略導(dǎo)致內(nèi)存泄露2012-11-11