HorizontalScrollView 横向显示图片
mHorizontalScrollView = (HorizontalScrollView) findViewById(R.id.hori_img);
mGallery = (LinearLayout) findViewById(R.id.id_gallery);
for (int i = 0; i < mDatas.size(); i++) {
View view = LayoutInflater.from(Share.this).inflate(
R.layout.activity_index_gallery_item, mGallery, false);
ImageView img = (ImageView) view
.findViewById(R.id.id_index_gallery_item_image);
img.setImageResource(mDatas.get(i));
ImageView txt = (ImageView) view
.findViewById(R.id.id_index_gallery_item_text);
view.setOnClickListener(mColumnListener);
mGallery.addView(view);
}
xml文件:
<HorizontalScrollView
android:id="@+id/hori_img"
android:layout_below="@+id/framelayou"
android:layout_width="match_parent"
android:scrollbars="none"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/id_gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
子item点击事件
private OnClickListener mColumnListener = new OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < mGallery.getChildCount(); i++) {
View localView = mGallery.getChildAt(i);
ImageView txt = (ImageView) localView
.findViewById(R.id.id_index_gallery_item_text);
if (localView != v) {
txt.setVisibility(View.GONE);
} else {
txt.setVisibility(View.VISIBLE);
share_ev_content.setText(spellStr.getStr(time, footName));
sign_img.setImageResource(mDatas.get(i));
}
}
}
};