我定义了一个扩展 LinearLayout 的视图,我想将它放入 ViewAnimator 中。麻烦的是,它没有出现。我没有为布局使用 XML,所以我有一个扩展 LinearLayout 的类,例如:
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);
}
然后在我的活动中添加它:
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);
但它没有显示。我敢肯定,我错过了一些非常明显的东西。