使用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样式不一样的。