I am trying to display an image at different scales within an
ImageView which is part of a larger LinearLayout.  Unfortunately, when
trying to calculate scaling factors, I am unable to read the
ImageView's dimensions.  The following code displays "Screen: 0, 0" in
the TextView, rather than the dimensions of the ImageView, as
expected.

I have tried this in 2.0 and 2.1.

What am I doing wrong?


ViewZoom.java: (included files left out for brevity)

public class ViewZoom extends Activity {
    ImageView mIv = null;
    TextView mTv = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mIv = (ImageView)findViewById(R.id.image);
        mTv = (TextView)findViewById(R.id.text);
    }

    @Override
    protected void onResume()
    {
        super.onResume();

        int screenWidth = mIv.getWidth();
        int screenHeight = mIv.getHeight();

        mTv.setText("Screen: " + screenWidth + ", " + screenHeight +
"\n");
    }
}


main.xml:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android";
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:id="@+id/image"/>

    <TextView
        android:layout_height="fill_parent"
        android:layout_width="wrap_content"
        android:layout_weight="1"
        android:id="@+id/text"/>

</LinearLayout>


Thank-you for your consideration.

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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to