Android仿京东分类模块左侧分类条目效果

作者:siyadong1 时间:2022-09-09 04:35:34 

本文实例为大家分享了Android仿京东左侧分类条目效果的具体代码,供大家参考,具体内容如下


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("内衣配饰");
 goodsList.add("家用电器");
 goodsList.add("手机数码");
 goodsList.add("电脑办公");
 goodsList.add("个护化妆");
 goodsList.add("母婴频道");
 goodsList.add("食物生鲜");
 goodsList.add("酒水饮料");
 goodsList.add("家居家纺");
 goodsList.add("酒水饮料");
 goodsList.add("整车车品");
 goodsList.add("运动户外");
 goodsList.add("图书");
 goodsList.add("钟表");
 goodsList.add("居家生活");
 goodsList.add("珠宝饰品");
 goodsList.add("音像制品");
 goodsList.add("家具建材");
 goodsList.add("计生情趣");
 goodsList.add("营养保健");
 goodsList.add("奢侈礼品");
 goodsList.add("生活服务");
 goodsList.add("旅游出行");

//动态生成每一个条目
 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());
 }
};

//改变点击条目的位置,居中
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);

}

//改变点击条目的颜色
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>

效果图:

Android仿京东分类模块左侧分类条目效果

来源:http://blog.csdn.net/u013680097/article/details/52767194

标签:Android,京东,分类
0
投稿

猜你喜欢

  • java 创建自定义数组

    2022-09-02 11:18:45
  • Spring @value用法示例详解

    2022-09-29 03:03:48
  • springboot拦截器Interceptor的使用,你都了解吗

    2023-01-01 21:53:40
  • 一个依赖搞定 Spring Boot 接口防盗刷的流程分析

    2023-06-01 16:46:41
  • Docker 存储驱动详细介绍

    2023-12-21 03:18:34
  • Java装饰器设计模式_动力节点Java学院整理

    2023-11-11 03:03:10
  • Java浅析枚举类的使用

    2023-11-10 14:12:58
  • java实现在原有日期时间上加几个月或几天

    2023-08-06 16:39:48
  • C#实现微信跳一跳小游戏的自动跳跃助手开发实战

    2022-12-11 02:49:08
  • 让C# Excel导入导出 支持不同版本Office

    2023-01-11 05:30:53
  • 详解Android中Notification通知提醒

    2023-09-10 09:57:19
  • 详解Java实践之建造者模式

    2023-01-14 23:03:13
  • 一篇文章带你玩转Spring bean的终极利器

    2022-08-20 10:47:33
  • spring mvc路径匹配原则详解

    2021-07-23 06:34:27
  • Spring Boot常用注解(经典干货)

    2023-11-24 22:29:10
  • Java Bean与xml互相转换的方法分析

    2021-08-12 13:34:00
  • Android多线程+单线程+断点续传+进度条显示下载功能

    2023-08-13 15:48:26
  • android之datepicker控件的用法

    2021-12-26 04:07:31
  • C#检查foreach判读是否为null的方法

    2021-10-28 01:37:24
  • Spring Boot 项目发布到 Tomcat 服务器的操作步骤

    2023-10-28 09:39:05
  • asp之家 软件编程 m.aspxhome.com