Android Custom View Spacing
Im trying to make a custom view that will have a dynamic number of pages (1-3) that each contain a dynamic number of child views (3-6). The pages aren't actually defined, they are just virtual groups of the child views. One page fits across the screen width.
My problem is that I can't space the children equally without using child.setMinimumWidth(screenWidth / mChildrenPerPage)
, but this makes them too high. How can I keep them at the original height AND space them out equally. Here is my code
mIconWidth = screenWidth / mChildrenPerPage;
for (int i = 0; i < mPages; i++) {
for (int j = 0; j < mChildrenPerPage; j++) {
View icon = layoutInflater.inflate(R.layout.child, this, false);
((ImageView)icon).setImageDrawable(resources.getDrawable(R.drawable.some_icon));
icon.setMinimu开发者_如何学编程mWidth(mIconWidth);
addView(icon);
}
}
I had to set up an xml layout and set the layout_weight manually.
精彩评论