本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下
实现思路:首先说下布局,整个是一个横向的线性布局,左边是一个ScrollView,右边是一个FrameLayout,在代码中动态向ScrollView中添加TextView,然后根据TextView的点击事件使用Fragment替换FrameLayout
首先看下布局:
MainActivity代码:
public class MainActivity extends FragmentActivity implements View.OnClickListener { private String[] titles={"常用分类","潮流女装","品牌男装","内衣配饰","家用电器","手机数码","电脑办公","个护化妆","母婴频道","食物生鲜","酒水饮料","家居家纺","整车车品","鞋靴箱包","运动户外","图书","玩具乐器","钟表","居家生活","珠宝饰品","音像制品","家具建材","计生情趣","营养保健","奢侈礼品","生活服务","旅游出行"}; private ScrollView mScrollView; private FrameLayout mFrameLayout; //装装ScrollView的item的TextView的数组 private TextView[] textViewArray; //装ScrollView的item的数组 private View[] views; Context context; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); cOntext=this; textViewArray=new TextView[titles.length]; views=new View[titles.length]; initView(); getSupportFragmentManager().beginTransaction().replace(R.id.framelayout,new FragmentOne()).commit(); } private void initView() { mScrollView= (ScrollView) findViewById(R.id.scrollview); addView(); changeTextColor(0); mFrameLayout= (FrameLayout) findViewById(R.id.framelayout); } /** * 给ScrollView添加子View */ private void addView() { LinearLayout mLinearLayout= (LinearLayout) findViewById(R.id.linearlayout); View view; for(int x=0;x
源码等上传上去会再次发布链接,如果那里写的不好,欢迎私信,评论指导
源码下载:Scroll+Fragment仿京东分类效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。