Java Code Examples for android.widget.ImageView#setX()

The following examples show how to use android.widget.ImageView#setX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditVideoActivity.java    From WeiXinRecordedDemo with MIT License 6 votes vote down vote up
/**
 * 初始化表情
 */
private void initExpression() {

    int dp80 = (int) getResources().getDimension(R.dimen.dp80);
    int dp10 = (int) getResources().getDimension(R.dimen.dp10);
    for (int x = 0; x < expressions.length; x++) {
        ImageView imageView = new ImageView(this);
        imageView.setPadding(dp10, dp10, dp10, dp10);
        final int result = expressions[x];
        imageView.setImageResource(result);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(windowWidth / 4, dp80));
        imageView.setX(x % 4 * windowWidth / 4);
        imageView.setY(x / 4 * dp80);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rl_expression.setVisibility(View.GONE);
                iv_icon.setImageResource(R.mipmap.icon);
                addExpressionToWindow(result);
            }
        });
        rl_expression.addView(imageView);
    }
}
 
Example 2
Source File: PolygonView.java    From AndroidDocumentScanner with MIT License 5 votes vote down vote up
private ImageView getImageView(int x, int y) {
    ImageView imageView = new ImageView(context);
    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    imageView.setLayoutParams(layoutParams);
    imageView.setImageResource(R.drawable.circle);
    imageView.setX(x);
    imageView.setY(y);
    imageView.setOnTouchListener(new TouchListenerImpl());
    return imageView;
}
 
Example 3
Source File: MapActivity.java    From WiFi-RTT-Trilateration with MIT License 5 votes vote down vote up
private void movePin(double x, double y, double z) {
    //  todo this is currently hard coded for 2D setups

    final ImageView ImageView_BitmapView = findViewById(R.id.map);
    final ImageView ImageView_Pin = findViewById(R.id.pin);
    ImageView_Pin.setVisibility(View.VISIBLE);

    //  0,0 point is 82.4427% down the image and 2.336% from the left of the image
    float x_image_offset = (ImageView_BitmapView.getWidth() * 0.02336f);
    float y_image_offset = (ImageView_BitmapView.getHeight() * 0.824427f);

    x_image_offset = ImageView_BitmapView.getX() + x_image_offset;
    y_image_offset = ImageView_BitmapView.getY() + y_image_offset;

    float pin_width = ImageView_Pin.getWidth();
    float pin_height = ImageView_Pin.getHeight();
    float x_pin_offset = (pin_width / 2.0f);
    float y_pin_offset = (pin_height) - (5.0f / 72.0f * pin_height); //  There are a few pixels at the bottom of the pin
    //  Account for the fact that the Pin is pointing to the lower middle of the image view
    float pinOriginX = x_image_offset - x_pin_offset;
    float pinOriginY = y_image_offset - y_pin_offset;
    //ImageView_Pin.setX(pinOriginX);
    //ImageView_Pin.setY(pinOriginY);

    float floorWidth = ImageView_BitmapView.getWidth() * (1772.0f / 3982.0f);
    float floorHeight = ImageView_BitmapView.getHeight() * (1488.0f / 2096.0f);

    float scaledX = (float) (x / 8370.0f * floorWidth);
    float scaledY = (float) (y / 7000.0f * floorHeight);
    ImageView_Pin.setX(pinOriginX + scaledX);
    ImageView_Pin.setY(pinOriginY - scaledY);
}
 
Example 4
Source File: TransferHeaderBehavior.java    From apkextractor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull ImageView child, @NonNull View dependency) {
    // 计算X轴坐标
    if (mOriginalHeaderX == 0) {
        this.mOriginalHeaderX = dependency.getWidth() / 2 - child.getWidth() / 2;
    }
    // 计算Y轴坐标
    if (mOriginalHeaderY == 0) {
        mOriginalHeaderY = dependency.getHeight() - child.getHeight();
    }
    //X轴百分比
    float mPercentX = dependency.getY() / mOriginalHeaderX;
    if (mPercentX >= 1) {
        mPercentX = 1;
    }
    //Y轴百分比
    float mPercentY = dependency.getY() / mOriginalHeaderY;
    if (mPercentY >= 1) {
        mPercentY = 1;
    }

    float x = mOriginalHeaderX - mOriginalHeaderX * mPercentX;
    if (x <= child.getWidth()) {
        x = child.getWidth();
    }
    // TODO 头像的放大和缩小没做

    child.setX(x);
    child.setY(mOriginalHeaderY - mOriginalHeaderY * mPercentY);
    return true;
}
 
Example 5
Source File: TrainActionActivity.java    From shortrain with MIT License 5 votes vote down vote up
private void addTrainToScreen(Rect trainRect) {
    rootView = new FrameLayout(this);
    engineView = addTrain(trainRect, TrainView.ENGINE, rootView);
    for (int i = 0; i < NUMBER_OF_CARS; i++) {
        carsView.add(addTrain(trainRect, TrainView.CAR, rootView));
    }

    rootView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fadeOutActivity();
        }
    });

    float iconToWidthFactor = 0.34f;
    ImageView startRoof = new ImageView(this);
    startRoof.setImageResource(R.drawable.long_start_point_roof);
    int trainRectSize = (int) (trainRect.width() * (1f - iconToWidthFactor));
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(trainRectSize, trainRectSize);
    startRoof.setX(trainRect.left + trainRect.width() * iconToWidthFactor / 2 - 15);
    startRoof.setY(trainRect.top + trainRect.width() * iconToWidthFactor / 2);
    rootView.addView(startRoof, lp);

    startRoof.setAlpha(0f);
    startRoof.animate()
            .alpha(1f)
            .setInterpolator(new DecelerateInterpolator())
            .setDuration(500)
            .start();

    setContentView(rootView);
}
 
Example 6
Source File: TransitionCompat.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 开始执行bitmap的动画效果,这里从透明度100%开始渐变
 * @param activity
 */
private static void startBitmapAnimation(Activity activity) {
	float fraction = 0.8f;//设置动画的比率,这个动画会先于屏幕动画完成,屏幕动画的比率是1f
	final ImageView bitmapImageView = getThumbnailOriginalImageView(activity);
	/**
	 * 开始设定view开始时的大小和坐标位置
	 */
	LayoutParams orginalParams = new LayoutParams(mWidth, mHeight);
	ViewGroup rootView = (ViewGroup)(activity.getWindow().getDecorView());
	rootView.addView(bitmapImageView, orginalParams);
	bitmapImageView.setX(mStartX);
	bitmapImageView.setY(mStartY);

	final Rect finalBounds = new Rect(0, 0, 
			(int)(ActivityOptionsCompatICS.getScreenWidth(activity) * fraction),
			(int)(ActivityOptionsCompatICS.getScreenHeight(activity) * fraction));
	/**
	 * 这里可以设置动画的持续时间,开始延迟,添加监听器
	 */
	final ViewAnim anim = new ViewAnim();
	anim.setDuration((long) (mAnimTime * fraction));
	anim.setStartDelay(mStartDelay);
	anim.addListener(mViewAnimListener);
	anim.setTimeInterpolator(mInterpolator);
	bitmapImageView.post(new Runnable() {
		
		@Override
		public void run() {
			/**其实这里可以计算偏移量的,但因为是从不透明到透明,最后的位置对于动画影响相当小,所以为了效率
			 * 就没有像sceneTransitionAnimation中一样进行详细的计算。如果真的有需求可以参考
			 * sceneTransitionAnimation中的计算方式,二者是完全一样的。
			 */
			anim.startViewSimpleAnim(bitmapImageView, finalBounds, 0, 0, 1f, 0f);
		}
	});
}
 
Example 7
Source File: TransitionCompat.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 开始执行bitmap的动画效果,这里从透明度100%开始渐变
 * @param activity
 */
private static void startBitmapAnimation(Activity activity) {
	float fraction = 0.8f;//设置动画的比率,这个动画会先于屏幕动画完成,屏幕动画的比率是1f
	final ImageView bitmapImageView = getThumbnailOriginalImageView(activity);
	/**
	 * 开始设定view开始时的大小和坐标位置
	 */
	LayoutParams orginalParams = new LayoutParams(mWidth, mHeight);
	ViewGroup rootView = (ViewGroup)(activity.getWindow().getDecorView());
	rootView.addView(bitmapImageView, orginalParams);
	bitmapImageView.setX(mStartX);
	bitmapImageView.setY(mStartY);

	final Rect finalBounds = new Rect(0, 0, 
			(int)(ActivityOptionsCompatICS.getScreenWidth(activity) * fraction),
			(int)(ActivityOptionsCompatICS.getScreenHeight(activity) * fraction));
	/**
	 * 这里可以设置动画的持续时间,开始延迟,添加监听器
	 */
	final ViewAnim anim = new ViewAnim();
	anim.setDuration((long) (mAnimTime * fraction));
	anim.setStartDelay(mStartDelay);
	anim.addListener(mViewAnimListener);
	anim.setTimeInterpolator(mInterpolator);
	bitmapImageView.post(new Runnable() {
		
		@Override
		public void run() {
			/**其实这里可以计算偏移量的,但因为是从不透明到透明,最后的位置对于动画影响相当小,所以为了效率
			 * 就没有像sceneTransitionAnimation中一样进行详细的计算。如果真的有需求可以参考
			 * sceneTransitionAnimation中的计算方式,二者是完全一样的。
			 */
			anim.startViewSimpleAnim(bitmapImageView, finalBounds, 0, 0, 1f, 0f);
		}
	});
}
 
Example 8
Source File: LockscreenViewService.java    From Android-LockScreenSample-DisableHomeButtonKey with Apache License 2.0 5 votes vote down vote up
private void settingLockView() {
    mBackgroundLayout = (RelativeLayout) mLockscreenView.findViewById(R.id.lockscreen_background_layout);
    mBackgroundInLayout = (RelativeLayout) mLockscreenView.findViewById(R.id.lockscreen_background_in_layout);
    mBackgroundLockImageView = (ImageView) mLockscreenView.findViewById(R.id.lockscreen_background_image);
    mForgroundLayout = (RelativeLayout) mLockscreenView.findViewById(R.id.lockscreen_forground_layout);
    mShimmerTextView = (ShimmerTextView) mLockscreenView.findViewById(R.id.shimmer_tv);
    (new Shimmer()).start(mShimmerTextView);
    mForgroundLayout.setOnTouchListener(mViewTouchListener);

    mStatusBackgruondDummyView = (RelativeLayout) mLockscreenView.findViewById(R.id.lockscreen_background_status_dummy);
    mStatusForgruondDummyView = (RelativeLayout) mLockscreenView.findViewById(R.id.lockscreen_forground_status_dummy);
    setBackGroundLockView();

    DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
    mDeviceWidth = displayMetrics.widthPixels;
    mDevideDeviceWidth = (mDeviceWidth / 2);
    mBackgroundLockImageView.setX((int) (((mDevideDeviceWidth) * -1)));

    //kitkat
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int val = LockscreenUtil.getInstance(mContext).getStatusBarHeight();
        RelativeLayout.LayoutParams forgroundParam = (RelativeLayout.LayoutParams) mStatusForgruondDummyView.getLayoutParams();
        forgroundParam.height = val;
        mStatusForgruondDummyView.setLayoutParams(forgroundParam);
        AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F);
        alpha.setDuration(0); // Make animation instant
        alpha.setFillAfter(true); // Tell it to persist after the animation ends
        mStatusForgruondDummyView.startAnimation(alpha);
        RelativeLayout.LayoutParams backgroundParam = (RelativeLayout.LayoutParams) mStatusBackgruondDummyView.getLayoutParams();
        backgroundParam.height = val;
        mStatusBackgruondDummyView.setLayoutParams(backgroundParam);
    }
}
 
Example 9
Source File: TransitionCompat.java    From ActivityOptionsICS with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 开始执行bitmap的动画效果,这里从透明度100%开始渐变
 * @param activity
 */
private static void startBitmapAnimation(Activity activity) {
	float fraction = 0.8f;//设置动画的比率,这个动画会先于屏幕动画完成,屏幕动画的比率是1f
	final ImageView bitmapImageView = getThumbnailOriginalImageView(activity);
	/**
	 * 开始设定view开始时的大小和坐标位置
	 */
	LayoutParams orginalParams = new LayoutParams(mWidth, mHeight);
	ViewGroup rootView = (ViewGroup)(activity.getWindow().getDecorView());
	rootView.addView(bitmapImageView, orginalParams);
	bitmapImageView.setX(mStartX);
	bitmapImageView.setY(mStartY);

	final Rect finalBounds = new Rect(0, 0, 
			(int)(ActivityOptionsCompatICS.getScreenWidth(activity) * fraction),
			(int)(ActivityOptionsCompatICS.getScreenHeight(activity) * fraction));
	/**
	 * 这里可以设置动画的持续时间,开始延迟,添加监听器
	 */
	final ViewAnim anim = new ViewAnim();
	anim.setDuration((long) (mAnimTime * fraction));
	anim.setStartDelay(mStartDelay);
	anim.addListener(mViewAnimListener);
	anim.setTimeInterpolator(mInterpolator);
	bitmapImageView.post(new Runnable() {
		
		@Override
		public void run() {
			/**其实这里可以计算偏移量的,但因为是从不透明到透明,最后的位置对于动画影响相当小,所以为了效率
			 * 就没有像sceneTransitionAnimation中一样进行详细的计算。如果真的有需求可以参考
			 * sceneTransitionAnimation中的计算方式,二者是完全一样的。
			 */
			anim.startViewSimpleAnim(bitmapImageView, finalBounds, 0, 0, 1f, 0f);
		}
	});
}
 
Example 10
Source File: songSliderThumb.java    From Android-Music-Player with MIT License 4 votes vote down vote up
public songSliderThumb(Context context, int width, int height,int ID) {
    super(context, width, height);
    this.ID = ID;
    setBackgroundColor(0x0000000);
    //SongSliderImg = new songSliderImg(width,height,0,0);
    RaidiusSqure = new radiusSqure(width,height,0,0,width*0.1f);
    RaidiusSqure.setColor(0xFFFFFFFF);

    name = textImg.getFMText(getContext(),"DEMO", Ui.cd.getHt(16));

    back = thumbBack.getFMview(getContext(),false);
    back.setSize(width - Ui.cd.getHt(2),height - Ui.cd.getHt(2));
    back.setX(Ui.cd.getHt(1));
    back.setY(Ui.cd.getHt(1));
    back.setClickable(false);
    addView(back);

    Iv = new ImageView(context){
        @Override
        protected void onDraw(Canvas canvas) {
            canvas.clipPath(back.img.mask);
            super.onDraw(canvas);
        }
    };
    Iv.setLayoutParams(new FrameLayout.LayoutParams(width - Ui.cd.getHt(2),height - Ui.cd.getHt(2)));
     addView(Iv);
    Iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
    Iv.setBackgroundColor(0x00FFFFFF);
    Iv.setX(Ui.cd.getHt(1));
    Iv.setY(Ui.cd.getHt(1));
    //setImg("3.png");

    ring = thumbRing.getFMview(getContext(),false);
    ring.setSize(width,height);
    ring.setClickable(false);
    addView(ring);
    if(android.os.Build.VERSION.SDK_INT <= 18){
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

   // addView(name);
}
 
Example 11
Source File: TransitionCompat.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 设定结束动画,bitmap从透明度0f变为1f
 * @param activity
 */
private static void endBitmapAnimation(Activity activity) {
	final ImageView bitmapImageView = getThumbnailOriginalImageView(activity);
	bitmapImageView.setVisibility(View.INVISIBLE);
	/**
	 * 开始设定view开始时的大小和坐标位置
	 */
	LayoutParams orginalParams = new LayoutParams(
			ActivityOptionsCompatICS.getScreenWidth(activity), 
			ActivityOptionsCompatICS.getScreenHeight(activity));
	
	ViewGroup rootView = (ViewGroup)(activity.getWindow().getDecorView());
	rootView.addView(bitmapImageView, orginalParams);
	bitmapImageView.setX(0);
	bitmapImageView.setY(0);
	/**
	 * 根据两个activity是否是全屏来计算开始的坐标和偏移量
	 * 从全屏切换到不全屏会出现位置偏移,这里进行处理
	 */
	final int finalOffsetY;
	boolean isFinalFullScreen = ActivityOptionsCompatICS.isFullScreen(activity);
	if (mIsStartFullScreen == false && isFinalFullScreen == true) {
		finalOffsetY = ActivityOptionsCompatICS.getStatusBarHeight(activity);
	}
	else {
		finalOffsetY = 0;
	}
	final Rect finalBounds = new Rect(mStartX, mStartY, mStartX + mWidth,mStartY + mHeight);
	/**
	 * 这里可以设置动画的持续时间,开始延迟,添加监听器
	 */
	final ViewAnim anim = new ViewAnim();
	anim.setDuration((long) (mAnimTime));
	anim.setStartDelay(mStartDelay);
	anim.addListener(mViewAnimListener);
	anim.setTimeInterpolator(mInterpolator);
	bitmapImageView.post(new Runnable() {
		
		@Override
		public void run() {
			anim.startViewSimpleAnim(bitmapImageView, finalBounds, 0, finalOffsetY, 0f, 1f);
		}
	});
}
 
Example 12
Source File: TransitionCompat.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 设定结束动画,bitmap从透明度0f变为1f
 * @param activity
 */
private static void endBitmapAnimation(Activity activity) {
	final ImageView bitmapImageView = getThumbnailOriginalImageView(activity);
	bitmapImageView.setVisibility(View.INVISIBLE);
	/**
	 * 开始设定view开始时的大小和坐标位置
	 */
	LayoutParams orginalParams = new LayoutParams(
			ActivityOptionsCompatICS.getScreenWidth(activity), 
			ActivityOptionsCompatICS.getScreenHeight(activity));
	
	ViewGroup rootView = (ViewGroup)(activity.getWindow().getDecorView());
	rootView.addView(bitmapImageView, orginalParams);
	bitmapImageView.setX(0);
	bitmapImageView.setY(0);
	/**
	 * 根据两个activity是否是全屏来计算开始的坐标和偏移量
	 * 从全屏切换到不全屏会出现位置偏移,这里进行处理
	 */
	final int finalOffsetY;
	boolean isFinalFullScreen = ActivityOptionsCompatICS.isFullScreen(activity);
	if (mIsStartFullScreen == false && isFinalFullScreen == true) {
		finalOffsetY = ActivityOptionsCompatICS.getStatusBarHeight(activity);
	}
	else {
		finalOffsetY = 0;
	}
	final Rect finalBounds = new Rect(mStartX, mStartY, mStartX + mWidth,mStartY + mHeight);
	/**
	 * 这里可以设置动画的持续时间,开始延迟,添加监听器
	 */
	final ViewAnim anim = new ViewAnim();
	anim.setDuration((long) (mAnimTime));
	anim.setStartDelay(mStartDelay);
	anim.addListener(mViewAnimListener);
	anim.setTimeInterpolator(mInterpolator);
	bitmapImageView.post(new Runnable() {
		
		@Override
		public void run() {
			anim.startViewSimpleAnim(bitmapImageView, finalBounds, 0, finalOffsetY, 0f, 1f);
		}
	});
}
 
Example 13
Source File: TransitionCompat.java    From ActivityOptionsICS with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 设定结束动画,bitmap从透明度0f变为1f
 * @param activity
 */
private static void endBitmapAnimation(Activity activity) {
	final ImageView bitmapImageView = getThumbnailOriginalImageView(activity);
	bitmapImageView.setVisibility(View.INVISIBLE);
	/**
	 * 开始设定view开始时的大小和坐标位置
	 */
	LayoutParams orginalParams = new LayoutParams(
			ActivityOptionsCompatICS.getScreenWidth(activity), 
			ActivityOptionsCompatICS.getScreenHeight(activity));
	
	ViewGroup rootView = (ViewGroup)(activity.getWindow().getDecorView());
	rootView.addView(bitmapImageView, orginalParams);
	bitmapImageView.setX(0);
	bitmapImageView.setY(0);
	/**
	 * 根据两个activity是否是全屏来计算开始的坐标和偏移量
	 * 从全屏切换到不全屏会出现位置偏移,这里进行处理
	 */
	final int finalOffsetY;
	boolean isFinalFullScreen = ActivityOptionsCompatICS.isFullScreen(activity);
	if (mIsStartFullScreen == false && isFinalFullScreen == true) {
		finalOffsetY = ActivityOptionsCompatICS.getStatusBarHeight(activity);
	}
	else {
		finalOffsetY = 0;
	}
	final Rect finalBounds = new Rect(mStartX, mStartY, mStartX + mWidth,mStartY + mHeight);
	/**
	 * 这里可以设置动画的持续时间,开始延迟,添加监听器
	 */
	final ViewAnim anim = new ViewAnim();
	anim.setDuration((long) (mAnimTime));
	anim.setStartDelay(mStartDelay);
	anim.addListener(mViewAnimListener);
	anim.setTimeInterpolator(mInterpolator);
	bitmapImageView.post(new Runnable() {
		
		@Override
		public void run() {
			anim.startViewSimpleAnim(bitmapImageView, finalBounds, 0, finalOffsetY, 0f, 1f);
		}
	});
}