Thumbnail Does Not Fill_parent As Expected
Solution 1:
I think the image is now displayed at 100%. If you want to stretch it to the full width, add the following line to the urlImageView xml:
android:scaleType="fitCenter"
CenterInside does the following: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
Check the documentation for more info on scaling.
Solution 2:
In your getView
method, you either need to manually apply LayoutParams to the inflated view, or else use inflate(myResource, parent, false)
instead of inflate(myResource, null)
to prevent your xml layout params from being overwritten. In your case, myResource
is R.layout.list_item_user_video
.
Then you can use
if (convertView==null)
convertView =
mInflater.inflate(R.layout.list_item_user_video, parent, false);
EDIT:
OK, it looks like ImageViews cannot in XML be automatically scaled to fit a certain width without distortion: https://stackoverflow.com/a/13925725/506796
Therefore, you must scale them after inflating the view. First you need to know the aspect ratio of the image (width/height). Since you seem to have a constant aspect ratio, you could just make this a static final float variable which will be much easier.
Then you need to know how wide the listview is in pixels. Again, you're in luck since your listview fills the width of the screen. (This is easier, because it would be tricky to measure the listview's width--you would have to do it after layout completes its first pass.) You can get the screen width in the adapter constructor with
screenWidth = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getWidth()
You can also create a single set of layout params to apply to all of your image views. In your adapter constructor:
LinearLayout.LayoutParamsimageParams=newLayoutParams(screenWidth, (int)(screenWidth/aspectRaio));
You can apply these params to the image view in getView
.
Post a Comment for "Thumbnail Does Not Fill_parent As Expected"