Android: alignment after scaling and size changed



I have a view which defines its width and height accordingly to layout dimensions (via ViewTreeObserver). I have another two ImageViews (wrapped in the RelativeLayouts). I need this two images be aligned to the top and bottom of the first view. They do, but use old view dimensions, not the corrected ones: so there is a gap between the views, when central gets smaller.


Here is an image of what I mean:


enter image description here


And the code:



@Override
public void onGlobalLayout() {
layoutWidth = layout.getWidth(); \\ main layout
layoutHeight = layout.getHeight();
LayoutParams params = arrows.getLayoutParams();
params.width = layoutHeight/3;
params.height = layoutHeight/3;
arrows.setLayoutParams(params);
LayoutParams paramseyes = eyes.getLayoutParams();
paramseyes.width = layoutHeight/4;
eyes.setLayoutParams(paramseyes);
mouth.setLayoutParams(paramseyes);

/*
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams
(paramseyes);
lp.addRule(RelativeLayout.ABOVE, R.id.arrows);
eyes.setLayoutParams(lp); ... nah, it didnt work
*/

removeOnGlobalLayoutListener(arrows, this);
}


the XML:



<ee.st.running.arrowwidgt
android1:id="@+id/arrows"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_centerInParent="true"
android:dial="@drawable/hourglass1"
android:hand_hour="@drawable/hours"
android:hand_minute="@drawable/minuts"
android:scaleType="fitXY"
android1:src="@drawable/hourglass1" />

<RelativeLayout
android1:id="@+id/eyes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android1:layout_above="@id/arrows" >

<ImageView
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_centerInParent="true"
android1:src="@drawable/eyes" />

</RelativeLayout>

<RelativeLayout
android1:id="@+id/mouthset"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android1:layout_below="@id/arrows"
android:layout_centerHorizontal="true"
>
<ImageView

android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android1:layout_centerHorizontal="true"
android1:src="@drawable/mouth"
/>
</RelativeLayout>


This arrows view is big (for multiple screens support I just scale it to certain size later).


No comments:

Post a Comment