本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下
实现思路:首先说下布局,整个是一个横向的线性布局,左边是一个ScrollView,右边是一个FrameLayout,在代码中动态向ScrollView中添加TextView,然后根据TextView的点击事件使用Fragment替换FrameLayout
首先看下布局:
<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="horizontal" tools:context="mit(); } } /** * 改变textView的颜色 * @param id */ private void changeTextColor(int id) { for (int i = 0; i < textViewArray.length; i++) { if(i!=id){ textViewArray[i].setBackgroundResource(android.R.color.transparent); textViewArray[i].setTextColor(0xff000000); }else { textViewArray[id].setBackgroundResource(android.R.color.white); textViewArray[id].setTextColor(0xffff5d5e); } } } /** * 改变栏目位置 */ private void changeTextLocation(int index) { //views[clickPosition].getTop()针对其父视图的顶部相对位置 int x = (views[index].getTop() - mScrollView.getHeight() / 2); mScrollView.smoothScrollTo(0, x); } }
源码等上传上去会再次发布链接,如果那里写的不好,欢迎私信,评论指导
源码下载:Scroll+Fragment仿京东分类效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。