转换为double值为整数而不进行四舍五入

时间:2016-12-02 12:11:55

标签: android integer double rounding

我根据屏幕的百分比给出视图高度。但是视图只能获得整数值。如何在不舍入数字的情况下转换整数值。我根据屏幕计算。当double值变为整数值时,屏幕上的舍入为空白。

public class TutorialFragment extends BaseFragment {

private double mScreenHeight;

private double bgBlueHeight;

private double bgGrayHeight;

private double textHeight;

private double mPathHeight;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    mView = inflater.inflate(R.layout.fragment_tutorial, container, false);

    setTutorialPages();

    return mView;

}

private void setBackgroundGray() {

    ImageView bgGray = (ImageView) mView.findViewById(R.id.bg_gray_tutorial);

    bgGray.getLayoutParams().height = (int) bgGrayHeight;

    bgGray.requestLayout();

}

private void setBackgroundBlue() {

    ImageView bgBlue = (ImageView) mView.findViewById(R.id.tutorial_dotted_blue_bg);

    bgBlue.getLayoutParams().height = (int) bgBlueHeight;

    bgBlue.requestLayout();

}

private void defaultScreen() {

    DefaultScreen.sharedInstance(getContext()).setDefaultScreen();

    mScreenHeight =  DefaultScreen.sharedInstance(getContext()).getScreenHeight();

    bgBlueHeight = mScreenHeight * 0.30;

    bgGrayHeight = mScreenHeight * 0.34;

    mPathHeight = mScreenHeight * 0.06;

    textHeight = mScreenHeight - bgBlueHeight - bgGrayHeight - mPathHeight;

}

    private void setText(String text) {

    TextView textView = (TextView) mView.findViewById(R.id.txt_tutorial);

    textView.setText(text);

    textView.getLayoutParams().height = (int) textHeight;

    textView.requestLayout();

}

private void setTutorialPages(){

    defaultScreen();

    setBackgroundBlue();

    setBackgroundGray();

    setPath();

}

}

0 个答案:

没有答案