在Java上更改图像宽度

时间:2011-07-29 10:46:53

标签: java android size invisible

嗨我把这个评论添加到代码中,当我按下时显示背景,但它显示图像全部工作除了,图像太小,但图像大小对应于设备的大小,我怎么能设置大小,或强制它

setBackgroundResource(R.drawable.slider_bg);

有完整的代码

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)

我会给你一个小例子,随意调整你的需求:

int width = 1024;
int height = 768;
FrameLayout fl = (FrameLayout) findViewById(R.id.mainframe);

fl.setLayoutParams(new FrameLayout.LayoutParams(width, height));

如果你想要你可以使用match_parrent而不是宽度和高度ofc,或xml可以做的任何其他事情