Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-26 Thread Hand Green
I got it.
Thank you very much!

2013/1/26 lbendlin 

> Keep track of the banner height elsewhere (at the point where it gets
> measured and rendered),  and then use that measurement to specify the image
> height , and then through the aspect ratio, calculate the image width and
> the x-position of the image.
>
> If the images are subviews of the banner, then you could even override the
> banner's onLayout, rather than the one for the images.
>
>
>
> On Saturday, January 26, 2013 6:47:48 AM UTC-5, Greenhand wrote:
>>
>> Although I can keep the ratio, I do not know what my background height is
>> from parameters.
>> Could you give me some code snippetss?
>>
>> lbendlin於 2013年1月26日星期六UTC+**8下午7時33分50秒寫道:
>>
>>> Now that you have extended the object you can change the calculations
>>>  for measure to achieve your desired effect while keeping the image aspect
>>> ratio.
>>
>>  --
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en




Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-26 Thread lbendlin
Keep track of the banner height elsewhere (at the point where it gets 
measured and rendered),  and then use that measurement to specify the image 
height , and then through the aspect ratio, calculate the image width and 
the x-position of the image.

If the images are subviews of the banner, then you could even override the 
banner's onLayout, rather than the one for the images.



On Saturday, January 26, 2013 6:47:48 AM UTC-5, Greenhand wrote:
>
> Although I can keep the ratio, I do not know what my background height is 
> from parameters.
> Could you give me some code snippetss?
>
> lbendlin於 2013年1月26日星期六UTC+8下午7時33分50秒寫道:
>
>> Now that you have extended the object you can change the calculations 
>>  for measure to achieve your desired effect while keeping the image aspect 
>> ratio.
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en




Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-26 Thread Greenhand
Although I can keep the ratio, I do not know what my background height is 
from parameters.
Could you give me some code snippetss?

lbendlin於 2013年1月26日星期六UTC+8下午7時33分50秒寫道:

> Now that you have extended the object you can change the calculations  for 
> measure to achieve your desired effect while keeping the image aspect ratio.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en




Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-26 Thread lbendlin
Now that you have extended the object you can change the calculations  for 
measure to achieve your desired effect while keeping the image aspect ratio.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en




Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-26 Thread Hand Green
I use dp. As far as I know, although I use dp to specify the height, it
still cannot resize dynamically according to the width.

2013/1/26 skink 

> Greenhand wrote:
> > To Piren:
> > Thank you. Assigning a specific height to the parent works.
> > The drawback is doing so is a little like hard code.
> > I would like a way to let android resize them dynamically since not all
> > sreen widths are the same.
> >
> >
> >
>
> did you specify the height as XXXpx?
>
> if so, use XXXdp (device independent pixels)
>
> pskink
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en




Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-25 Thread skink


Greenhand wrote:
> To Piren:
> Thank you. Assigning a specific height to the parent works.
> The drawback is doing so is a little like hard code.
> I would like a way to let android resize them dynamically since not all
> sreen widths are the same.
>
>
>

did you specify the height as XXXpx?

if so, use XXXdp (device independent pixels)

pskink

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en




Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-25 Thread Greenhand
I followed your advice to create a MyImageView class:
public class MyImageView extends ImageView{
 private static final String TAG = MyImageView.class.getSimpleName();
 public MyImageView(Context context, AttributeSet attrs) {
  super(context, attrs);
 }
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  int width = MeasureSpec.getSize(widthMeasureSpec);
  int height = MeasureSpec.getSize(heightMeasureSpec);
  Log.d(TAG, "onMeasure: "+width+"*"+height);
 }
 @Override
 protected void onLayout(boolean changed, int left, int top, int right, int 
bottom) {
  super.onLayout(changed, left, top, right, bottom);
  Log.d(TAG, "onLayout: "+left+" "+top+" "+right+" "+bottom);
 }
}
And changed my layout to use MyImageView:
http://schemas.android.com/apk/res/android";
xmlns:tools="http://schemas.android.com/tools";
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">










 
In the log file, it printed:
D/MyImageView(3866): onMeasure: 480*724
D/MyImageView(3866): onMeasure: 480*724
D/MyImageView(3866): onMeasure: 480*724
D/MyImageView(3866): onMeasure: 480*724
D/MyImageView(3866): onMeasure: 240*724
D/MyImageView(3866): onMeasure: 120*724
D/MyImageView(3866): onLayout: 0 0 480 80
D/MyImageView(3866): onLayout: 120 0 360 120
D/MyImageView(3866): onLayout: 180 30 300 90
D/MyImageView(3866): onMeasure: 480*724
D/MyImageView(3866): onMeasure: 480*724
D/MyImageView(3866): onMeasure: 480*724
D/MyImageView(3866): onMeasure: 480*724
D/MyImageView(3866): onMeasure: 240*724
D/MyImageView(3866): onMeasure: 120*724
D/MyImageView(3866): onLayout: 0 0 480 80
D/MyImageView(3866): onLayout: 120 0 360 120
D/MyImageView(3866): onLayout: 180 30 300 90
Could you give me more detailed instructions on how to override these two 
methods and leverage the parameters to achieve what I would like to do?
 
To Piren: 
Thank you. Assigning a specific height to the parent works. 
The drawback is doing so is a little like hard code. 
I would like a way to let android resize them dynamically since not all 
sreen widths are the same.
 

lbendlin於 2013年1月26日星期六UTC+8上午3時57分31秒寫道:

> The quickest solution would be to create a custom imageview that extends 
> imageview, and then handle the onLayout and onMeasure yourself.
>
> On Friday, January 25, 2013 12:59:38 AM UTC-5, Greenhand wrote:
>>
>> Because if I changed the two "inner" image views to match_parent, they 
>> will expand the background imageview and its parent (RelativeLayout). It 
>> did not work.
>>  
>> What I would like to do is let the inner imageviews resized automatically 
>> to "exactly match" the background. If it is smaller, it will stretch to the 
>> height of the background. If it is bigger, it will shrink to the height of 
>> the background.
>>  
>> By the way, I think the "match_parent" attribute in Android is literally 
>> misleading because it will make its parent bigger to "match_parent".
>> 2013/1/25 Piren 
>>
>>> if every imageview's height is wrap_content, why are you expecting them 
>>> all to be the same (when all their sources are different sizes)? 
>>> AdjustViewBounds isnt a magical property :)
>>> the two "inner" imageviews should be match_parent.
>>>
>>> it's also a good idea to define scaleType since it has the most 
>>> relevancy when talking about keeping the image ratio.
>>>
>>>
>>>  
>>>
>>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en




Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-25 Thread Piren
I've done many things exactly like that, worked fine for me. You can always 
just assign a specific height to the parent, it will prevent any child from 
expanding it. And can always just implement you own view that matches its 
size to its parent.
Either way, by using wrap_content you'll never achieve what you want. 

On Friday, January 25, 2013 7:59:38 AM UTC+2, Greenhand wrote:
>
> Because if I changed the two "inner" image views to match_parent, they 
> will expand the background imageview and its parent (RelativeLayout). It 
> did not work.
>  
> What I would like to do is let the inner imageviews resized automatically 
> to "exactly match" the background. If it is smaller, it will stretch to the 
> height of the background. If it is bigger, it will shrink to the height of 
> the background.
>  
> By the way, I think the "match_parent" attribute in Android is literally 
> misleading because it will make its parent bigger to "match_parent".
> 2013/1/25 Piren >
>
>> if every imageview's height is wrap_content, why are you expecting them 
>> all to be the same (when all their sources are different sizes)? 
>> AdjustViewBounds isnt a magical property :)
>> the two "inner" imageviews should be match_parent.
>>
>> it's also a good idea to define scaleType since it has the most relevancy 
>> when talking about keeping the image ratio.
>>
>>
>>  
>>
>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en




Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-25 Thread lbendlin
The quickest solution would be to create a custom imageview that extends 
imageview, and then handle the onLayout and onMeasure yourself.

On Friday, January 25, 2013 12:59:38 AM UTC-5, Greenhand wrote:
>
> Because if I changed the two "inner" image views to match_parent, they 
> will expand the background imageview and its parent (RelativeLayout). It 
> did not work.
>  
> What I would like to do is let the inner imageviews resized automatically 
> to "exactly match" the background. If it is smaller, it will stretch to the 
> height of the background. If it is bigger, it will shrink to the height of 
> the background.
>  
> By the way, I think the "match_parent" attribute in Android is literally 
> misleading because it will make its parent bigger to "match_parent".
> 2013/1/25 Piren >
>
>> if every imageview's height is wrap_content, why are you expecting them 
>> all to be the same (when all their sources are different sizes)? 
>> AdjustViewBounds isnt a magical property :)
>> the two "inner" imageviews should be match_parent.
>>
>> it's also a good idea to define scaleType since it has the most relevancy 
>> when talking about keeping the image ratio.
>>
>>
>>  
>>
>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en




Re: [android-developers] Re: android imageview stretch to background height and keep ratio

2013-01-24 Thread Hand Green
Because if I changed the two "inner" image views to match_parent, they will
expand the background imageview and its parent (RelativeLayout). It did not
work.

What I would like to do is let the inner imageviews resized automatically
to "exactly match" the background. If it is smaller, it will stretch to the
height of the background. If it is bigger, it will shrink to the height of
the background.

By the way, I think the "match_parent" attribute in Android is literally
misleading because it will make its parent bigger to "match_parent".
2013/1/25 Piren 

> if every imageview's height is wrap_content, why are you expecting them
> all to be the same (when all their sources are different sizes)?
> AdjustViewBounds isnt a magical property :)
> the two "inner" imageviews should be match_parent.
>
> it's also a good idea to define scaleType since it has the most relevancy
> when talking about keeping the image ratio.
>
>
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en