Android小知识——添加多个View

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值