Android小知识——添加多个View
2016-05-30 11:55
295 查看
使用HorizontalScrollView里面含有LinearLayout向里面添加多个View
XML文件:
<HorizontalScrollView
android:id="@+id/hor"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginRight="50dp"
android:background="#fff"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/top_ll"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
java文件:
final ImageView img_iv;
final TextView title_tv;
final View childView;
childView = LayoutInflater.from(this).inflate(R.layout.item_list, null);
img_iv = (ImageView) childView.findViewById(R.id.img_iv);
title_tv = (TextView) childView.findViewById(R.id.title_tv);
title_tv.setText(str);
top_ll.addView(childView);
final int j = i;
childView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {// 横向滑动的点击事件 点击改变了之后
mPullRefreshListView.setSelected(false);
notifyButtonState(j);
String heh = TempTool.getData().get(str);
HttpTool.getImages(MyApplication.getContext(), heh, "" + 1, HttpTool.OPERATION_RESET);
}
});
上面的Java文件里面有多少个item,就可以循环多少次。
获取里面某个View的样式设置
private void notifyButtonState(int index) {
for (int i = 0; i < 12; i++) {
View view = top_ll.getChildAt(i);
ImageView img_iv = (ImageView) view.findViewById(R.id.img_iv);
TextView title_tv = (TextView) view.findViewById(R.id.title_tv);
if (i != index) {
img_iv.setVisibility(View.INVISIBLE);
title_tv.setTextColor(Color.parseColor("#aaaaaa"));
} else {
img_iv.setVisibility(View.VISIBLE);
title_tv.setTextColor(Color.parseColor("#666666"));
}
}
}
调用这个方法,表示当前的item设置的样式,其他的item样式不一样的。
XML文件:
<HorizontalScrollView
android:id="@+id/hor"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginRight="50dp"
android:background="#fff"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/top_ll"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
java文件:
final ImageView img_iv;
final TextView title_tv;
final View childView;
childView = LayoutInflater.from(this).inflate(R.layout.item_list, null);
img_iv = (ImageView) childView.findViewById(R.id.img_iv);
title_tv = (TextView) childView.findViewById(R.id.title_tv);
title_tv.setText(str);
top_ll.addView(childView);
final int j = i;
childView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {// 横向滑动的点击事件 点击改变了之后
mPullRefreshListView.setSelected(false);
notifyButtonState(j);
String heh = TempTool.getData().get(str);
HttpTool.getImages(MyApplication.getContext(), heh, "" + 1, HttpTool.OPERATION_RESET);
}
});
上面的Java文件里面有多少个item,就可以循环多少次。
获取里面某个View的样式设置
private void notifyButtonState(int index) {
for (int i = 0; i < 12; i++) {
View view = top_ll.getChildAt(i);
ImageView img_iv = (ImageView) view.findViewById(R.id.img_iv);
TextView title_tv = (TextView) view.findViewById(R.id.title_tv);
if (i != index) {
img_iv.setVisibility(View.INVISIBLE);
title_tv.setTextColor(Color.parseColor("#aaaaaa"));
} else {
img_iv.setVisibility(View.VISIBLE);
title_tv.setTextColor(Color.parseColor("#666666"));
}
}
}
调用这个方法,表示当前的item设置的样式,其他的item样式不一样的。
相关文章推荐
- winform异型不规则界面设计的实现方法
- 在ASP.NET 2.0中操作数据之二十:定制数据修改界面
- Android中设置只有程序第一次运行才显示的界面实现思路
- hta 实现的五子棋界面
- android开发之欢迎界面的小例子
- C#中载入界面的常用方法
- Android绘制炫酷引导界面
- android编程实现局部界面动态切换的方法
- Android判断现在所处界面是否为home主桌面的方法
- Android用户注册界面
- Android编程实现泡泡聊天界面实例详解(附源码)
- android 引导界面的实现方法
- VC 界面库皮肤库相关信息珍藏
- 在ASP.NET 2.0中操作数据之二十:定制数据修改界面
- Android中界面实现全屏显示的两种方式
- 简单做出不丑设计
- extmail 界面修改
- QT程序启动界面的使用
- The Book of Qt 4 翻译: 2.2 界面和处理逻辑的分离