2017-07-31 156 views
1

我得到一个问题,从原生的Android JAVA代码转换代码Xamarin C#的Android代码: 我有一个类ThumbnailStrip:必须从原生的Android转换代码Xamarin的Android

  • 如何设定方向
  • LayOutParameters
  • OnClickListener

    class ThumbnailStrip extends FrameLayout { 
        Context con; 
        Rotator rotator; 
        CustomImageView images; 
        int count; 
        Bitmap bitmap; 
        double viewHeight, viewWidth; 
        private boolean isDown; 
        private float X,Y,dX,dY,diffX,diffY; 
        private boolean NEXT,PREVIOUS; 
        LinearLayout thumbLayout; 
    
        public ThumbnailStrip(Context context, SfRotator _imageSlider, double height, double width) { 
        super(context); 
        con = context; 
        rotator = _imageSlider; 
        thumbLayout = new LinearLayout(context); 
        if (rotator.getNavigationStripPosition() == NavigationStripPosition.Top || rotator.getNavigationStripPosition() == NavigationStripPosition.Bottom) 
         thumbLayout.setOrientation(LinearLayout.HORIZONTAL); 
        else 
         thumbLayout.setOrientation(LinearLayout.VERTICAL); 
        if (thumbLayout.getOrientation() == LinearLayout.HORIZONTAL) { 
         viewHeight = height-10; 
         viewWidth = width/5; 
        } else { 
         viewHeight = height/5; 
         viewWidth = width-10; 
        } 
        createThumbnails(con); 
    } 
    
    Timer thumbTimer;boolean thumbStart,isDynamicView; 
    public ThumbnailStrip(Context context, AttributeSet attrs) { 
        super(context, attrs); 
    } 
    
    private void createThumbnails(Context con) { 
    
        if (rotator.getDataSource() != null) { 
         count = rotator.getDataSource().size(); 
         for (int i = 0; i < count; i++) { 
          View view; 
          if(rotator.getAdapter()!=null && rotator.getAdapter().getThumbnailView(rotator,i)!=null) { 
           view = rotator.getAdapter().getThumbnailView(rotator, i); 
           isDynamicView = true; 
          } 
          else { 
    
           if(rotator.getDataSource().get(i).getContent()!=null) { 
            view = rotator.getDataSource().get(i).getContent(); 
            isDynamicView = false; 
           } 
           else 
           { 
            ImageView imageView = new ImageView(getContext()); 
            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
            int resID = getResources().getIdentifier(rotator.getDataSource().get(i).getImageContent(), "drawable", getContext().getPackageName()); 
            bitmap = BitmapFactory.decodeResource(getResources(), resID); 
            imageView.setImageBitmap(bitmap); 
            view=imageView; 
            isDynamicView = false; 
    
    
           } 
          } 
          view.setLayoutParams(new ViewGroup.LayoutParams(rotator.getWidth(),rotator.getHeight())); 
          images = new CustomImageView(con,view , (float) viewWidth, (float) viewHeight,isDynamicView); 
          images.setClickable(true); 
          images.setPadding(6, 0, 0, 0); 
          if(thumbLayout.getOrientation()==LinearLayout.VERTICAL) { 
           images.setPadding(6, 6, 0, 0); 
          } 
          images.setIndex(i); 
          if (i == rotator.getSelectedIndex()) { 
           images.setSelectedImage(true); 
          } 
          images.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 
          LayoutParams itemLayout; 
          itemLayout = new LayoutParams((int) viewWidth, (int) (viewHeight), Gravity.CENTER_VERTICAL); 
          itemLayout.setMargins(6, 6, 0, 0); 
          thumbLayout.addView(images, itemLayout); 
    
    
    //Especially I don't know how to set OnCliCkListener,Please help me with a solution. 
    
          images.setOnClickListener(new OnClickListener() { 
           @Override 
           public void onClick(View v) { 
            if (rotator.isEnableAutoPlay()) { 
             rotator.isAnimationinteracted = true; 
            } 
            final CustomImageView imgView = (CustomImageView) v; 
            if (imgView.getIndex() > rotator.getSelectedIndex()) 
             rotator.setPlayDirection(PlayDirection.MoveBackward); 
            else 
             rotator.setPlayDirection(PlayDirection.MoveForward); 
            if (imgView.getIndex() != rotator.getSelectedIndex()) { 
             rotator.setSelectedIndex((imgView).getIndex()); 
             if (rotator.isEnableAutoPlay()) { 
              thumbStart = true; 
             } 
            } 
           } 
          }); 
         } 
         this.addView(thumbLayout); 
        } 
    } 
    } 
    

请帮助我转换。在Xamarin

回答

0

布局参数是这样的:

LinearLayout linear = new LinearLayout(this); 
       ImageView image = new ImageView(this); 

    LinearLayout.LayoutParams linearLayoutParams = new 
    LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, 
    LinearLayout.LayoutParams.FillParent); 
    linear.LayoutParameters = linearLayoutParams; 

Cheking方向是这样的:

if(linear.Orientation == Orientation.Horizontal){ 

    } 

的onClick监听器在Java将转换为这样的活动

image.Click += (sender, e) => { 

    }; 
+0

@suraj ForOnClickListener我有一个疑问PlayDirection和isAnimationinteracted.Can你可以解释一下这个部分。 – Rabhia

+0

你需要在这个类的Rotator和CustomImageView上看到这些代码才能知道。这是自定义的,除非我看到代码,否则我无法向您解释。 – Rai

0
images.Click += (sender, e) => 
{ 

    if (rotator.isEnableAutoPlay()) 
    { 
     rotator.isAnimationinteracted = true; 
    } 

    CustomImageView imgView = (CustomImageView)view; 
    if (imgView.getIndex() > rotator.getSelectedIndex()) 
     rotator.playDirection = PlayDirection.MoveBackward; 
    else 
     rotator.playDirection = PlayDirection.MoveForward; 
     if (imgView.getIndex() != rotator.getSelectedIndex()) 
     { 
      rotator.setSelectedIndex((imgView).getIndex()); 
      if (rotator.isEnableAutoPlay()) 
      { 
        thumbStart = true; 
      } 
     } 
}; 
相关问题