I have a n app widget that is pretty much working, with one quirk. I’ve got a LinearLayout in the widget, and I can add rows of my data to it just fine. There doesn’t seem to be any obvious way for me to tell how big the linear layout is and if a given row will fit, so I just add the entire data set (since it isn’t very large). The text in my layout gets cropped at the bottom, which is what I’d expect. However, the ImageView next to it is not being cropped, but is instead being scaled. It, frankly, looks goofy.
If there’s a way for me to tell if a row will fit in my LinearLayout, that would be great. If there’s a way I can tell it to just crop my image, that would be fine too. This is what the cropping looks like.
The layout for the rows I’m adding (if there’s a goof here, it’s probably from the anonymization I applied):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/checkbox"
android:layout_width="28sp"
android:layout_height="28sp"
android:src="@drawable/check_off"
android:layout_marginLeft="5dp"
android:layout_marginTop="1dp"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/textview"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="16sp"
android:minHeight="28sp"
android:paddingLeft="5dp"
android:layout_centerVertical="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/checkbox"/>
</RelativeLayout>
EDIT: The container for the rows is just a simple LinearLayout:
<LinearLayout
android:id="@+id/list_items"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_above="@id/logo"
android:layout_marginBottom="4dp"
android:padding="1dp"
android:orientation="vertical"
android:background="@drawable/widget_background"/>
It turns out that giving the RelativeLayout that corresponds to the row a specific height (30sp, for this layout) instead of “wrap_content” fixed the problem. The image now crops correctly.