android开发之动态给HorizontalScrollView添加被包含控件
2015-03-04 10:53
597 查看
这个标题起的有点意思,有些小伙伴也许看到这样的标题也是一愣一愣的,那么,我就给大伙解释解释一下。什么叫包含?包含,顾名思义包含者与被包含者没有直接关系,没有继承关系,不然那得叫继承。说到这里,我要给大伙展示的效果是什么呢?请看图:
这是还未包含任何控件:
这是已包含控件:
动态加载而且还不一样的被包含者,那怎么办?
第一步:先看看布局代码
第二步:动态添加第一个被包含控件
在此要扩展一点东西:
咋玩的!其实这是注解工具啦,那么,你要使用的话:
1、下载xUtils开源工具jar包:http://download.csdn.net/detail/dg41598/8435075
2、将下载的
3、在Activity类中的onCreate方法中:
4、声明类的全局变量范围中:
这样就省略了大量的findViewById()!
第三步:动态添加第二、三….个被包含控件
这是还未包含任何控件:
这是已包含控件:
动态加载而且还不一样的被包含者,那怎么办?
第一步:先看看布局代码
<HorizontalScrollView android:id="@+id/hsv_file" android:layout_below="@id/tv_off_cache" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/s_23dp" > //动态添加被包含控件于此处 <LinearLayout android:id="@+id/ll_file" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > </LinearLayout> </HorizontalScrollView>
第二步:动态添加第一个被包含控件
@ViewInject(R.id.ll_file) LinearLayout ll_file; //item_total_downing.xml就是第一个被包含的控件布局文件 View rl_total_downing = getLayoutInflater().inflate(R.layout.item_total_downing, null); TextView iv_downingNum = (TextView) rl_total_downing.findViewById(R.id.iv_downingNum); TextView tv_downing = (TextView) rl_total_downing.findViewById(R.id.tv_downing); ll_file.addView(rl_total_downing); //添加第一个被包含控件
在此要扩展一点东西:
@ViewInject(R.id.ll_file) LinearLayout ll_file;
咋玩的!其实这是注解工具啦,那么,你要使用的话:
1、下载xUtils开源工具jar包:http://download.csdn.net/detail/dg41598/8435075
2、将下载的
3、在Activity类中的onCreate方法中:
setContentView(R.layout.personal_center_layout); ViewUtils.inject(this);
4、声明类的全局变量范围中:
@ViewInject(R.id.ll_file) LinearLayout ll_file;
这样就省略了大量的findViewById()!
第三步:动态添加第二、三….个被包含控件
List<CourseItemBean> courseItemBeans = new ArrayList<CourseItemBean>(); private BitmapUtils bitmapUtils = new BitmapUtils(this);; //动态添加已下载文件到HorizontalScrollView当中 for(int i = 0;i<courseItemBeans.size();i++) { final CourseItemBean itemEntity = courseItemBeans.get(i); //horizontalscrollview_list_item.xml就是第二、三...个被包含的控件布局文件 final RelativeLayout item = (RelativeLayout) getLayoutInflater().inflate(R.layout.horizontalscrollview_list_item, null); ImageView icon = (ImageView) item.findViewById(R.id.icon); //设置已下载文件的图片 //压缩图片 bitmapUtils.display(icon,itemEntity.getImg()); TextView tv_downing = (TextView) item.findViewById(R.id.tv_downing); tv_downing.setText(itemEntity.getTitle()); //设置已下载文件的标题 //因为第一个下标位置被添加了,因此以后的第二、三...都得在其下标上加1 ll_file.addView(item,i+1); }
相关文章推荐
- Android实战简易教程-第四枪(ScrollView和HorizontalScrollView动态添加控件并提供事件监听)
- Android实战简易教程<四>(ScrollView和HorizontalScrollView动态添加控件并提供事件监听)
- 【Android 开发】:UI控件之 ScrollView垂直滚动控件 和 HorizontalScrollView水平滚动控件的使用
- HorizontalScrollView动态添加控件并可以移动到点击的控件的位置
- Android HorizontalScrollView 水平滑动 在listview上面动态添加图片
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
- Android动态布局,并动态为TextView控件设置drawableLeft、drawableRight等属性添加图标
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
- 使用C# + Xamarin开发Android应用-- 动态添加控件
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
- HorizontalScrollView 动态添加View后 滚动到最后一个 最右边
- Android 自定义 HorizontalScrollView 图片控件
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
- 【Android游戏开发之六】在SurfaceView中添加系统控件,并且相互交互数据!
- 安卓开发笔记——自定义HorizontalScrollView控件(实现QQ5.0侧滑效果)
- 【Android游戏开发之六】在SurfaceView中添加系统控件,并且相互交互数据!