如何使用可能的幻灯片列表视图设计android弹出窗口

时间:2016-07-27 06:00:46

标签: android xml user-interface android-studio

可能是这种设计,

弹出窗口,可能有幻灯片列表视图 如果单击箭头按钮移动到下一个视图

请通过编码提出任何想法......

enter image description here

2 个答案:

答案 0 :(得分:1)

使用Here.中的查看寻呼机指示器,并在其下方添加两个线性布局,并在coustom dailog和完成时使用它。

快乐的编码。

enter image description here

答案 1 :(得分:0)

我可能创造了...... 编码&这里参考

view pager reference

  1. 弹出窗口java代码

    public void popUpWindow() {
    
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.activity_main_investment_popup_pageadapter);
    
    dotsLayout = (LinearLayout) dialog.findViewById(R.id.layoutDots1);
    btnPrevious = (ImageButton) dialog.findViewById(R.id.btnPrevious);
    btnNext = (ImageButton) dialog.findViewById(R.id.btnNext);
    popUpClose = (ImageButton) dialog.findViewById(R.id.popUpClose);
    
    // adding bottom dots
    addBottomDots(0);
    
    viewPager = (ViewPager) dialog.findViewById(R.id.pager_popUP);
    // Pass results to ViewPagerAdapter Class
    adapter = new ViewPagerAdapter(context, list, ListTotalReturnPrice, population);
    // Binds the Adapter to the ViewPager
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(viewPagerPageChangeListener);
    
    dialog.show();
    
    btnNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int current = getSlideItem(+1);
            viewPager.setCurrentItem(current);
        }
    });
    
    btnPrevious.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // checking for last page
            // if last page home screen will be launched
            int current = getSlideItem(-1);
            viewPager.setCurrentItem(current);
        }
    });
    
    popUpClose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          dialog.cancel();
        }
    });
    
    }
    
    private int getSlideItem(int i) {
    return viewPager.getCurrentItem() + i;
    }
    
    private void addBottomDots(int currentPage) {
    dots = new TextView[list.size()];
    
    int colorsActive = Color.rgb(65, 87, 147);
    int colorsInactive = Color.rgb(217, 217, 217);
    
    dotsLayout.removeAllViews();
    for (int i = 0; i < dots.length; i++) {
        dots[i] = new TextView(context);
        dots[i].setText(Html.fromHtml("&#8226;"));
        dots[i].setTextSize(35);
        dots[i].setTextColor(colorsInactive);
        dotsLayout.addView(dots[i]);
    }
    
    if (dots.length > 0)
        dots[currentPage].setTextColor(colorsActive);
    }
    
  2. 2.viewpager更改监听器

        ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {
    
        @Override
        public void onPageSelected(int position) {
            addBottomDots(position);
        }
    
        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
    
        }
    
        @Override
        public void onPageScrollStateChanged(int arg0) {
    
        }
        };
    
    1. ViewPagerAdapter类

          class ViewPagerAdapter extends PagerAdapter {
          // Declare Variables
          Context context;
          String[] rank;
          String[] country;
          String[] population;
          LayoutInflater inflater;
      
          public ViewPagerAdapter(Context context, ArrayList<String> list, ArrayList<String> ListTotalReturnPrice, String[] population) {
          this.context = context;
          list = list;
          this.country = country;
          this.population = population;
          this.flag = flag;
          }
      
          @Override
          public int getCount() {
          return list.size();
          }
      
          @Override
          public boolean isViewFromObject(View view, Object object) {
          return view == ((LinearLayout) object);
          }
      
          @Override
          public Object instantiateItem(ViewGroup container, int position) {
      
          // Declare Variables
          TextView txtrank;
          TextView txtcountry;
          TextView txtpopulation;
      
          inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View itemView = inflater.inflate(R.layout.activity_main_investment_popup, container, false);
      
          // Locate the TextViews in viewpager_item.xml
          txtrank = (TextView) itemView.findViewById(R.id.popUpMenuTitle2);
          txtcountry = (TextView) itemView.findViewById(R.id.textView21);
          txtpopulation = (TextView) itemView.findViewById(R.id.textView25);
      
          // Capture position and set to the TextViews
          txtrank.setText(list.get(position));
          txtcountry.setText(ListTotalReturnPrice.get(position));
          // Add viewpager_item.xml to ViewPager
          ((ViewPager) container).addView(itemView);
      
          return itemView;
      }
      
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          // Remove viewpager_item.xml from ViewPager
          ((ViewPager) container).removeView((LinearLayout) object);
      
      }
      }
      
    2. 弹出xml

    3. enter image description here

      1. 查看寻呼机xml enter image description here