this is my first question.
I created a custom component: a RelativeLayout
with a TextView
at the bottom and two ImageView
above, which act as an element with two columns for the histogram. To set the strip height, I get the "available height" in onLayout()
, since the container height is minus the label:
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); mAvailHeight = getHeight()-findViewById(R.id.label).getHeight();
and then assign it (multiplied by 0.-1.) as the layout parameter for ImageView:
View bar = findViewById(R.id.bigBar); RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) bar.getLayoutParams(); rlp.height = Math.round((float)mAvailHeight * mBigBarHeight); }
The variable mBigBarHeight
(0.-1.) Can be set using this function:
public void setBigBarHeight(float value, float max) { mBigBarHeight = value / max; requestLayout();
Now. When I add one of these "HistogramBar" to onCreate()
and set the heights and labels, everything works as I expect. If I try to change them later, say onClickSomething:
bar.setBigBarHeight(25, 100); bar.setSmallBarHeight(50, 100); bar.setLabel("jjk");
only the label changes. I checked with the Hierarchy Viewer, and actually LayoutParams have changed. If I click, the changes will appear again.
The funny thing is that even if I do a โLoad View Hierarchyโ from the tool changes, it will be displayed (on the emulator) !! What's happening? This is strange? I want to do this in my code to make it work!
I could not find a similar question. Thanks.