I am trying to download a picture from a resource and display it in Imageview and then programmatically add it to the Layout.
LinearLayout tmp_layout = new LinearLayout(getApplicationContext()); tmp_layout.setOrientation(LinearLayout.HORIZONTAL); tmp_layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); tmp_layout.setGravity(Gravity.CENTER); linearLayout.addView(tmp_layout, params); TextView textView = new TextView(MessagesActivity.this); textView.setGravity(Gravity.RIGHT); //textView.setBackgroundResource(R.color.background_message_from); //textView.setText(message_enc_from_key); textView.setText(decrypt(hex2Byte(message_enc_from_key), private_key_my)); //textView.setText(date_time); textView.setTextSize(20); tmp_layout.addView(textView, params); ImageView tmp_img = new ImageView(getApplicationContext()); tmp_img.setImageResource(R.drawable.ic_face_black_24dp); tmp_layout.addView(tmp_img, params); The problem is that the textview is displayed, but imageview is not. What am I doing wrong?
tmp_layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));You have no effect, since you then addtmp_layoutwith new parameters:linearLayout.addView(tmp_layout, params);- Vladyslav Matviienko