I’ve defined a view that extends LinearLayout, which I want to put in a ViewAnimator. Trouble is, it doesn’t show up.
I’m not using XML for the layouts, so I have a class that extends LinearLayout, for example:
public class DetailView extends LinearLayout {
ImageView mImageView;
TextView mTxtName;
public DetailView(Context context) {
super(context);
mTxtName = new TextView(context);
LinearLayout.LayoutParams lpn = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lpn.setMargins(3,3,3,3);
mTxtName.setLayoutParams(lpn);
mTxtName.setTextAppearance(context, android.R.attr.textAppearanceMedium);
mImageView = new ImageView(context);
LinearLayout.LayoutParams lpi = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lpi.setMargins(10,10,10,10);
mImageView.setLayoutParams(lpi);
mImageView.setScaleType(ScaleType.CENTER_INSIDE);
mImageView.setImageResource(R.drawable.wait);
}
Then in my activity I add it thus:
va = new ViewAnimator(this);
detail = new DetailView(this);
detail.setOrientation(1);
LinearLayout.LayoutParams dLayout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);
va.setLayoutParams(dLayout);
va.addView(detail,0);
But it doesn’t show. I’m missing something stupidly obvious, I’m sure.
I think the problem is that you never call
addViewto add the childViewsinto yourViewGroup. It would be something like: