I had the same problem and found a solution. Hope this can be helpful. You need to set a fixed width if you want to achieve this effect. To find the actual viewing width, you need to measure it. So the complete solution:
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int height = view.getMeasuredHeight(); int width = view.getMeasuredWidth(); view.setLayoutParams(new LinearLayout.LayoutParams(width, height));
(Use LayoutParams for the type matching the type of the parent layout)
0neel source share