Question: I've an imageview with an icon on background, instead of generating all diferent sizes of icons for diferent sizes of screen i'm using only a big one and resizing it to fit the size I want.

If I set the layout\_height to any value android automatically resize the width to keep aspect ratio (what is good) but the placeholder keeps the original width and the new resized icon is centered in the space it was supposed to fit

To demonstrate the situation i took this print

[![enter image description here](https://i.stack.imgur.com/b5MaR.jpg)](https://i.stack.imgur.com/b5MaR.jpg)

both left and right icons have the same dimension in original file

```
<ImageView
            android:id="@+id/leftThumb"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_alignParentLeft="true"
            android:foregroundGravity="left"
            android:src="@drawable/ic_left_thumb" />

        <ImageView
            android:id="@+id/rightThumb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:src="@drawable/ic_right_thumb" />

```

setting only the imageview height and is it possible to make it resizes keeping gravity on left? (as in the print bellow)

[![enter image description here](https://i.stack.imgur.com/x9XpL.jpg)](https://i.stack.imgur.com/x9XpL.jpg)

Answer: 
You are using a so-called *dependent subquery.* These can sometime be very inefficient.

You can use this subquery to retrieve the max timestamp for each stock\_id value.

```
                   SELECT MAX(timestamp) timestamp, stock_id
                     FROM market
                    GROUP BY stock_id

```

Your compound primary key should make this quite fast because MySQL will do [a "loose index scan" to](https://dev.mysql.com/doc/refman/5.7/en/group-by-optimization.html#loose-index-scan) satisfy it. 

Then you can use this as a subquery, as follows:

```
  SELECT m.stock_id, m.timestamp, m.price
    FROM market m
    JOIN (
                   SELECT MAX(timestamp) timestamp, stock_id
                     FROM market
                    GROUP BY stock_id
         ) maxt on m.stock_id = maxt.stock_id AND m.timestamp = maxt.timestamp

```

This, too, should exploit your primary key.
You are using a so-called *dependent subquery.* These can sometimes be very inefficient, because the query planner repeats them for every value from the outer query (`m1.stock_id` in your case).

You can use this subquery to retrieve the max timestamp for each stock\_id value.

```
                   SELECT MAX(timestamp) timestamp, stock_id
                     FROM market
                    GROUP BY stock_id

```

Your compound primary key should make this quite fast because MySQL will do [a "loose index scan](https://dev.mysql.com/doc/refman/5.7/en/group-by-optimization.html#loose-index-scan)" to satisfy it. 

Then you can use it as a subquery, as follows:

```
  SELECT m.stock_id, m.timestamp, m.price
    FROM market m
    JOIN (
                   SELECT MAX(timestamp) timestamp, stock_id
                     FROM market
                    GROUP BY stock_id
         ) maxt on m.stock_id = maxt.stock_id AND m.timestamp = maxt.timestamp

```

This, too, should exploit your primary key. <https://use-the-index-luke.com/>