I am trying adding imageView programmatically, but don't make same size in different screens. I tried many scale codes, but don't have any good result.
screens: screens' image
here is my code:
public class Explore extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
View view = inflater.inflate(R.layout.tab, container, false);
LinearLayout linearLayout= new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
final float scale = view.getContext().getResources().getDisplayMetrics().density;
int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics());
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 82, getResources().getDisplayMetrics());
int lastWidth = (int) (width * scale + 0.5f);
int lastHeight = (int) (height * scale + 0.5f);
ImageView imageView = new ImageView(getActivity());
UrlImageViewHelper.setUrlDrawable(imageView, "https://example.com/example.jpg");
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(lastWidth, lastHeight);
imageView.setLayoutParams(lp);
linearLayout.addView(imageView);
return linearLayout;
}
}