开发者

Change size of FrameLayout when screen size has been found

开发者 https://www.devze.com 2023-03-22 18:35 出处:网络
At the moment I have a FrameLayout which will hold a preview of a picture taken. The size of this is determined in the layout xml file I created for it, at the moment its just set to fill_parent. Howe

At the moment I have a FrameLayout which will hold a preview of a picture taken. The size of this is determined in the layout xml file I created for it, at the moment its just set to fill_parent. However the image taken is at 4:3 aspect ratio, but this isn't always going to be the right aspect ratio for the users screen.

开发者_C百科

For example with my Xperia X10 which is 480 X 854, the 4:3 image taken by the camera always stretches to fit the FrameLayout.

What I want to do is change the size of the FrameLayout outside of the XML file so that it is 4:3 and a size appropriate for the users screen size. Any ideas?


I guess you are using an ImageView inside your FrameLayout to display the actual picture? In this case, use scaleType to define how the picture should be stretched.

You can set that in your XML, just use android:scaleType=".." inside your ImageView tag.


 Framelayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);
 lv.setLayoutParams(lp);

Try using the above code...

0

精彩评论

暂无评论...
验证码 换一张
取 消