图库:选定项目中的效果

Sol*_*ety 5 android android-gallery android-viewpager

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

在此输入图像描述

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

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

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

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

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

我正在开展一项活动.

J_S*_*zle 2

取决于您想要的行为。有些问题可以同时展开多个项目吗?您想要对视图进行分页(卡入到位)还是平滑滚动它们?

我的一个建议是为各个单元格创建一个自定义视图。然后以编程方式将它们添加到 Horizo​​ntalScrollView 对象中。

 HorizontalScrollView hsv = new HorizontalScrollView(activity);
 LinearLayout hll = new LinearLayout(activity);
 hll.setOrientation(LinearLayout.HORIZONTAL);
 for(int i=0;i<items.length();i++){
      hsv.addView(new CustomExpandView(item));
 }
Run Code Online (Sandbox Code Playgroud)

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);
        }

    });
}
Run Code Online (Sandbox Code Playgroud)