views:

346

answers:

0

Hey all,

This is a layout that I have defined in an app. As you can see, I would like the TextView "@details/image_time_counter" to be aligned with the bottom right of the image. Unfortunately, this is currently what shows - app - hierarchy viewer all - HV part 2. HierarchyViewer reports that the ImageView has bounds much bigger than what I am expecting. Can anyone explain these bounds, or just tell me how to make the bounds be the same as the image size?

Thanks, Hamy

PS - noticed that if I use android:src="@drawable/ss" then this ImageView works as expected. I am currently updating the src programmatically, as follows. Somewhere in this code is the real issue (I suspect scaleType or the bounds, but I cannot id the root cause)

    // Code that loads the image from network

    final StringBuffer urlString = new StringBuffer(Constants.Server_URL);
    urlString.append(Constants.Server_Latest_URI);
    urlString.append("?lot=");
    // urlString.append(lotId); // We only have one image feed, not one for
    // each lot
    urlString.append("fspot");

    URL url = null;
    try {
        url = new URL(urlString.toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    BitmapDrawable image = null;
    try {
        image = new BitmapDrawable(url.openStream());
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (image.getIntrinsicHeight() == -1) {
        Log.i("fspot", "Bad image returned from server url "
                + urlString.toString());
        return null;
    }

    // Code that updates the ImageView
    public void updateImage(final BitmapDrawable newImage) {
    runOnUiThread(new Runnable() {

        public void run() {
            final Calendar now = new GregorianCalendar();
            final StringBuffer time = new StringBuffer();
            time.append(now.get(Calendar.HOUR));
            time.append(":");
            final int min = now.get(Calendar.MINUTE);
            if (min < 10)
                time.append("0");
            time.append(min);
            time.append(":");
            final int sec = now.get(Calendar.SECOND);
            if (sec < 10)
                time.append("0");
            time.append(sec);

            imageTimeCounter_.setText(time.toString());
            imageTimeCounter_.invalidate();

            lotImage_.setImageDrawable(newImage);
            lotImage_.invalidate();
        }
    });
}



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >

    <!-- Edit: The @+details is not the issue, it's just a filtering 
         trick that let's you say R.details rather than having R.id 
         be massive, I am positive that my problem is not coming from the ids -->
    <TextView 
        android:id="@+details/lot_name"  
        android:layout_height="wrap_content" 
        android:gravity="center_horizontal"
        android:layout_width="fill_parent" 
        android:paddingTop="10dip"
        android:paddingBottom="13dip" 
        android:background="@color/light_gray"
        android:text="Towers Lot 1" 
        android:textSize="24dip"
        android:typeface="sans" />

    <TextView 
        android:id="@+details/spots_open"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:text="2" 
        android:textSize="26dip" 
        android:layout_marginLeft="35dip"
        android:layout_below="@details/lot_name" 
        android:textColor="@color/neon_green"
        android:textStyle="bold" />

    <TextView 
        android:id="@+details/spots_open_as_of"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:text="spots open as of " 
        android:textSize="20dip"
        android:layout_marginLeft="5dip" 
        android:layout_toRightOf="@details/spots_open"
        android:layout_alignBaseline="@details/spots_open" />

    <TextView 
        android:id="@+details/spot_time_counter"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:text="3" 
        android:layout_toRightOf="@details/spots_open_as_of"
        android:layout_alignBaseline="@details/spots_open" 
        android:textSize="20dip" />

    <ImageView 
        android:id="@+details/lot_image"
        android:layout_width="wrap_content" 
        android:layout_below="@details/spots_open_as_of"
        android:layout_centerHorizontal="true" 
        android:layout_height="wrap_content" />

    <TextView 
        android:id="@+details/image_time_counter"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_alignRight="@details/lot_image"
        android:layout_alignBottom="@details/lot_image" 
        android:text="this is a test" />

    <TextView 
        android:id="@+details/permits" 
        android:text="F Permit"
        android:textSize="10dip" 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" 
        android:layout_alignBottom="@details/lot_name"
        android:gravity="center_horizontal" />

</RelativeLayout>