Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
必须将代码从本机Android转换为Xamarin Android_Android_Xamarin.android - Fatal编程技术网

必须将代码从本机Android转换为Xamarin Android

必须将代码从本机Android转换为Xamarin Android,android,xamarin.android,Android,Xamarin.android,我在将本地Android JAVA代码转换为Xamarin C#Android代码时遇到问题: 我有一个类缩略图: 如何设置方向 布局参数 onclick侦听器 class ThumbnailStrip extends FrameLayout { Context con; Rotator rotator; CustomImageView images; int count; Bitmap bitmap; double viewHeight, viewWidth; p

我在将本地Android JAVA代码转换为Xamarin C#Android代码时遇到问题: 我有一个类缩略图:

  • 如何设置方向
  • 布局参数
  • onclick侦听器

    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);
        }
    }
    }
    
    class ThumbnailStrip扩展了FrameLayout{
    上下文con;
    旋转器;
    自定义图像查看图像;
    整数计数;
    位图;
    双视图高度、视图宽度;
    私家布尔isDown;
    私有浮点X,Y,dX,dY,diffX,diffY;
    私有布尔下一个,上一个;
    线性布局;
    公共缩略图条(上下文上下文、SfRotator\u imageSlider、双高、双宽){
    超级(上下文);
    con=上下文;
    旋转器=_图像滑块;
    thumbLayout=新的线性布局(上下文);
    if(rotator.getNavigationStripPosition()==NavigationStripPosition.Top | | rotator.getNavigationStripPosition()==NavigationStripPosition.Bottom)
    thumbLayout.setOrientation(LinearLayout.HORIZONTAL);
    其他的
    thumbLayout.setOrientation(LinearLayout.VERTICAL);
    if(thumbLayout.getOrientation()==LinearLayout.HORIZONTAL){
    viewHeight=height-10;
    视图宽度=宽度/5;
    }否则{
    viewHeight=高度/5;
    视图宽度=宽度-10;
    }
    创建缩略图(con);
    }
    计时器thumbTimer;布尔thumbStart,isDynamicView;
    公共缩略图条(上下文、属性集属性){
    超级(上下文,attrs);
    }
    私有void createThumbnails(上下文con){
    if(rotator.getDataSource()!=null){
    count=rotator.getDataSource().size();
    for(int i=0;irotator.getSelectedIndex())
    旋转器。设置播放方向(播放方向。向后移动);
    其他的
    旋转器。设置播放方向(播放方向。向前移动);
    if(imgView.getIndex()!=rotator.getSelectedIndex()){
    setSelectedIndex((imgView.getIndex());
    if(rotator.isEnableAutoPlay()){
    thumbStart=true;
    }
    }
    }
    });
    }
    此.addView(thumbLayout);
    }
    }
    }
    

请帮我转换。

Xamarin中的布局参数如下:

    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;
    if(linear.Orientation == Orientation.Horizontal){

    }
检查方向如下:

    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;
    if(linear.Orientation == Orientation.Horizontal){

    }
Java中的onCLick侦听器将转换为如下事件

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

    };

Xamarin中的布局参数如下所示:

    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;
    if(linear.Orientation == Orientation.Horizontal){

    }
检查方向如下:

    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;
    if(linear.Orientation == Orientation.Horizontal){

    }
Java中的onCLick侦听器将转换为如下事件

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

    };

@suraj ForOnClickListener我对PlayDirection和IsAnimationInteractivated有疑问。你能解释一下这部分吗。你需要看看这个类Rotator和CustomImageView上的代码才能知道。这是自定义的,除非我看到代码,否则我无法向您解释。@suraj ForOnClickListener我对PlayDirection和IsAnimationInteractivated有疑问。请您解释一下这一部分。您需要在这个类Rotator和CustomImageView上看到这些代码才能知道。这是自定义的,我不能解释给你,除非我看到代码。