I create an Activity like this:

final ImageView ivPic = new ImageView(this); ivPic.setImageResource(R.drawable.ic_menu_camera); ivPic.setAdjustViewBounds(true); ivPic.setScaleType(ImageView.ScaleType.FIT_XY); ivPic.setMinimumWidth(20); ivPic.setMinimumHeight(20); ivPic.setMaxHeight(25); ivPic.setMaxWidth(25); TextView tvDate = new TextView(this); tvDate.setText("fasfsafsafasfa sdfdsfsdfsdfds fsd fsdfs df sdf sdfsd fsd fsdfsd"); LinearLayout llImage = new LinearLayout(this); llImage.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); llImage.setOrientation(LinearLayout.HORIZONTAL); llImage.setPadding(10, 20, 10, 18); llImage.addView(tvDate); llImage.addView(ivPic); 

The problem is that the displayed text is pressed to the left, and the picture is also pressed to the left to the text, but I want the picture to be pressed to the right edge of the LinerLayout. How to press the ImageView to the right? Thank.

    1 answer 1

    There are several ways.

    For example, set the textview width to 0 and weight to 1

    Or place between the text and the Space image with the same parameters - width 0 and weight 1

    Or use FrameLayout and gravity