what I want to do in a view is have a textview and to the right of it, have another custom view X with the same height as the textview and have width=height:
+---------------------+---+
|A flexible string | X |
+---------------------+---+
My attempt so far is:
Inside the X class:
@Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
setMeasuredDimension(height,height);
Log.v("measure","width:"+height + " height:"+height);
}
and my xml:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/mytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"/>
<mystuff.X
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="@id/mytext"/>
</RelativeLayout>
The log statement prints out:
width:1073741823 height:1073741823
width:37 height:37
width:1073741823 height:1073741823
width:37 height:37
width:1073741823 height:1073741823
width:37 height:37
when the view is created and it fills the width of the screen:
+---------------------+-----------------+
|A flexible string | X |
+---------------------+-----------------+
I would greatly appreciate any help with this.
Thanks!
Ian
You are treating the measure specs as actual pixels. They are in fact the ints that represent “fill_parent”, “wrap_content”, etc.
What you want to do is: