Android: ImageView in Fragment (compatibility package): can't set width and height by code?

You have to understand the use of fragments here. You include the fragment in your XML with the width set to "fill_parent". The fragment in this case just returns the ImageView.It is as you would put the ImageView directly into your layout.

You have to set the pixel information in the XML of the fragment or you add the fragment programmatically You can find more information about scaling ImageViews here.

You have to understand the use of fragments here. You include the fragment in your XML with the width set to "fill_parent". The fragment in this case just returns the ImageView.It is as you would put the ImageView directly into your layout.

You have to set the pixel information in the XML of the fragment or you add the fragment programmatically. You can find more information about scaling ImageViews here.

Thank you: I use a fragment as I need to replace it with a different content by an animation as application goes on. Dividing the layout by fragments was a requirement too: fragments must stretch for different resolutions, while images should scale inside them. Beside if I explicit the image inside fragment in xml layout file, the image is always put on the top of the fragment thou I specify I want it in the center.

– Black Imp Oct 12 at 12:36 It is important to set the android:scaleType="centerCrop" option on the ImageView if you want it to be scaled. Can you post the code where you change the fragment? Then I can tell you what you have to fix in order to scale the image correctly.

– Franziskus Karsunke Oct 12 at 12:46 I'm still not changing fragment. By now I have simply to solve the issue to set specific dimension for image inside a fragment by code: if I don't create an ImageView by code inside the OnCreateView and use only xml, the application crashes. If I create the ImageView by code, I'm not able to set a different size than the one that fills the fragment.My idea was to leave some space between fragment border and image, setting explicitly image dimension by dp translated in px.

– Black Imp Oct 12 at 13:02 Have you tried using image. SetScaleType(ImageView.ScaleType. CENTER_CROP) in the onCreateView?

– Franziskus Karsunke Oct 12 at 14:01 I've put my image inside a LinearLayout and now I can set its width and height by the same code I've written above. By the way now there 's no way I can show the image vertically centered inside its fragment. Fragment in xml has width that fills parent while fixed height to 60dp.

The linear layout fills parent both vertically and horizontally. The image gravity is set to "center". – Black Imp Oct 127 at 9:03.

You have to understand the use of fragments here. You include the fragment in your XML with the width set to "fill_parent". The fragment in this case just returns the ImageView.

It is as you would put the ImageView directly into your layout. You have to set the pixel information in the XML of the fragment or you add the fragment programmatically. You can find more information about scaling ImageViews here.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions