-3

How to set width for image progragmaticall?

This is my code,

    txtone = (ImageView)findViewById(R.id.imageView);
    txttwo = (ImageView)findViewById(R.id.imageView2);
    height = metrics.heightPixels;
    width = metrics.widthPixels;
    if (height == 800 && width == 1217) {
    int a = txtone.getMeasuredWidth();
    txtone.getLayoutParams().width = 280;
    txttwo.getLayoutParams().width = 280;
    txtthree.getLayoutParams().width = 280;
    txtone.requestLayout();
    txttwo.requestLayout();
    txtthree.requestLayout();
Udhaya
  • 39
  • 10

1 Answers1

1

you try to use one of txttwo txtthree before actually initializing them. One of them is null, when you call

txttwo.getLayoutParams().width = 280;
txtthree.getLayoutParams().width = 280;

As for your code, you didn't initialize txtthree

Vladyslav Matviienko
  • 10,610
  • 4
  • 33
  • 52