I am not so sure why my custom viewgroup won't render the textview wihtin its child which is a linear layout:
This is my viewgroup code:
import android.content.Context;
import android.graphics.Color;
import android.graphics.RectF;
import android.view.View;
import android.view.ViewGroup;
public class noteLayout extends ViewGroup {
float leftOrientationSize = 0;
float rightOrientationSize=0;
public noteLayout(Context activityContext)
{
super(activityContext);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int numberOfChild = getChildCount();
for (int i = 0;i<numberOfChild;i++){
View childView = getChildAt(i);
float childHeight = (float) childView.getMeasuredHeight();
float childWidth = (float) childView.getMeasuredWidth();
RectF rect = new RectF();
rect.bottom = 300;
rect.top = 20;
rect.left = 50;
rect.right = (getWidth()/2)-20;
childView.layout((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom);
}
}
}
I have created a simple linear layout with a textview inside. This file is in xml and it is called test3.
Also, the following code is used to add the test3 layout into the custom viewgroup.
private void layoutNoteView() {
noteLayout noteLayout = new noteLayout(this);
noteLayout.addView((View) getLayoutInflater().inflate(R.layout.test3,null));
RelativeLayout.LayoutParams noteLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
noteLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
noteLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
}
noteLayoutParams.addRule(RelativeLayout.BELOW, R.id.StartRelativeLayout);
relativeLayoutMain.addView(noteLayout,noteLayoutParams);
}
My question is I am not so sure why my custom viewgroup won't even render the textview inside the linear layout. All it renders is just the linear layout of the test3 layout file. I am so desperately trying to figure out how can I get the textview to get rendered.
Please note that if I have a textView alone without putting it into the linearlayout, my custom viewgroup renders that textview perfectly fine. It only happens when I have it within a layout and then put it in my custom viewgroup layout.