如何设置背景图片的大小?

时间:2011-08-01 09:49:04

标签: java android

我需要一些帮助来设置android Java源代码的背景图像大小,这里是我想要添加的代码:setBackgroundResource(R.drawable.slider_bg_right);是我添加的行以添加背景,但是图像尺寸太小,我想编辑背景的大小。

switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mTracking = true;
        mTriggered = false;
        vibrate();
        if (leftHit) {
            mCurrentSlider = mLeftSlider;
            mOtherSlider = mRightSlider;
            mThreshold = isHorizontal() ? THRESHOLD : 1.0f - THRESHOLD;
            setGrabbedState(OnTriggerListener.LEFT_HANDLE);
      ----- setBackgroundResource(R.drawable.slider_bg_right); -------
        } else {
            mCurrentSlider = mRightSlider;
            mOtherSlider = mLeftSlider;
            mThreshold = isHorizontal() ? 1.0f - THRESHOLD : THRESHOLD;
            setGrabbedState(OnTriggerListener.RIGHT_HANDLE);
      ------ setBackgroundResource(R.drawable.slider_bg_left); -------
        }                  
        mCurrentSlider.setState(Slider.STATE_PRESSED);
        mCurrentSlider.showTarget();
        mOtherSlider.hide();
        break;
    }
}

1 个答案:

答案 0 :(得分:0)

尝试使用Bitmap.createScaledBitmap();在android中指定所需的宽度和高度。