Anroid 小记(dp->dx,measure(),PagerAdapter)

android:typeface="monospace"
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6, getResources().getDisplayMetrics());
View childView = createChildView(inflater, resources, BoothCenterItemData.defaultData[0]);
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
childView.measure(widthMeasureSpec, heightMeasureSpec);
int measuredHeight = childView.getMeasuredHeight();
public class BoothCenterAdapter extends PagerAdapter {
    private final List<BoothCenterItemView> itemViews;

    public BoothCenterAdapter(List<BoothCenterItemView> itemViews) {
        this.itemViews = itemViews;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = itemViews.get(position);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getCount() {
        return itemViews.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }
}
打赏