tags:

views:

383

answers:

2

I've got thumbnails which larger side is 70px (e.g 70x40 or 52x70).

I need to create a gray box 70x70px and put the thumbnail in it, so that image is aligned with the box at top vertically and center horizontally.

How to do that?

I've tried with an ImageView 70x70px, gray background, but image is not positioned as it should (it's in vertical and horizontal center, instead of vertical top and horizontal center).

I've also tried wrapping it with LinearLayout 70x70px, gray background and then positioning it, but then i get 1 or 2px line between LinearLayout and ImageView. I tried to set padding and margins to 0, but the gray line stays on...

A: 

Use a RelativeLayout. Set the background to be gray and the size to be 70px square. Put the ImageView as a child of the RelativeLayout, with android:layout_alignParentTop="true" and android:layout_centerHorizontal="true".

CommonsWare
I'm still getting 2px line between the pic and the top of the RelativeLayout.You can see what I'm talking about here: http://img706.imageshack.us/img706/2852/20100112144811.png
zorglub76
Without the images and layouts, I cannot really help much. Ensure that there is no transparent segment at the top of the image, that you're not applying padding or margins on the ImageView, etc.
CommonsWare
OK, the layout I'm working on is a list item. You can see XML file here: http://pastebin.com/m239fa5c and the screenshot of the resulting layout here: http://img706.imageshack.us/img706/2852/20100112144811.png
zorglub76
Btw, I've tried with zero padding and margins...
zorglub76
Make sure that when you inflate your row, you use inflate(R.layout.whatever, parent, false).
CommonsWare
I have `convertView = inflater.inflate(R.layout.result_list_row, ResultListActivity.this.getListView(), false);` but the result is still the same...
zorglub76
Your second parameter should be the `parent` parameter passed into getView() (or newView(), depending on which adapter you're using). I *think* that will be the same as what you have, but I recommend making the change to be sure. Get this wrong, and RelativeLayout gets cranky. Beyond that, I have no suggestions.
CommonsWare
..and again the same (when using "parent" instead of "getListView()")..Ok, I'll try to reproduce this behavior in a clean new project and then file it as a bug. If I manage to reproduce it, that is..
zorglub76
I reported it here: http://code.google.com/p/android/issues/detail?id=6020 There's also a project attached to the reported issue (if you'd like to play with it)
zorglub76
A: 

Damn!!

Of course, it was so simple: just had to add android:scaleType="fitStart" to ImageView - no need for all those layouts..

zorglub76
Actually - it doesn't work. fitStart aligns image to the upper left corner. But I gave up. Anyway, it looks better center-aligned...
zorglub76