微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 图库:选中项目中的效果

我需要一起滚动项目,所选项目应该向下扩展一部分.

我目前正在使用一个gallery(我尝试使用viewflow和viewpager,但这些项目之间有很大的空间),但我需要知道如何才能实现此效果.

我有2个想法,但我不知道如何实现它.

1)可扩展部分是LinearLayout,其中visibility = gone,当选择该项时,此布局应该是可见的. (图库没有“onItemSelectedListener”)

2)将每个元素视为一个片段(一旦我使用一个使用它的Viewpager,https://github.com/mrleolink/SimpleInfiniteCarousel)

它不一定是画廊,任何想法都是受欢迎的

我正在开展一项活动.

最佳答案
取决于您想要的行为.有些问题可以一次扩展多个项目吗?您是希望将视图分页(捕捉到位)还是平滑滚动它们?

我有一个建议是为单个单元格制作自定义视图.然后以编程方式将它们添加到Horizo​​ntalScrollView对象.

 horizontalscrollview hsv = new horizontalscrollview(activity);
 LinearLayout hll = new LinearLayout(activity);
 hll.setorientation(LinearLayout.HORIZONTAL);
 for(int i=0;i

CustomExpandView将用于您的单元格,可能是这样的……

public class CustomExpandView extends RelativeLayout implements OnClickListener {

MyActivity mActivity = null;
ImageView ivImage,ivOverImage;
RelativeLayout rlView;

public CustomExpandView(Context context) {
    super(context);
    initialize();
}

public CustomExpandView(Context context,AttributeSet attrs) {
    super(context,attrs);
    initialize();
}

public void initialize() {
    mActivity = (MyActivity) this.getContext();
    LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.custom_cell_expand,this,true);

            //you can initialize subviews here
    rlView = (RelativeLayout) getChildAt(0);
    ivImage = (ImageView) rlView.getChildAt(0);
    ivOverImage = (ImageView) rlView.getChildAt(1);

 rlView.setonFocuschangelistener(new OnFocuschangelistener(){

        @Override
        public void onFocusChange(View v,boolean hasFocus) {
            LinearLayout expand = v.findViewById(R.id.view_i_want_to_expand);
            if(hasFocus)
                expand.setVisibility(View.VISIBLE);
            else
                expand.setVisibility(View.GONE);
        }

    });
}

原文地址:https://www.jb51.cc/android/431006.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐