Reputation: 5566
Here is what I don't understand:
HorizontalScrollView scroll = new HorizontalScrollView(this);
scroll.setLayoutParams(new LayoutParams(getResources().getInteger(R.integer.dim_hand_width), getResources().getInteger(R.integer.dim_hand_height)));
HandLayout = new LinearLayout(this);
HandLayout.setOrientation(LinearLayout.HORIZONTAL);
HandLayout.setBackgroundColor(getResources().getColor(R.color.bg_hand));
HandLayout.setLayoutParams(new LayoutParams(getResources().getInteger(R.integer.dim_hand_width), getResources().getInteger(R.integer.dim_hand_height)));
scroll.addView(HandLayout);
for (int i = 0; i < 8; i++){
Button b = new Button(this);
b.setWidth(200);
HandLayout.addView(b);
}
This shows the ScrollView with all 8 buttons and it is scrollable.
However, when I replace the last few lines with:
for (int i = 0; i < 8; i++){
HeroCard hc = new HeroCard(this);
HandLayout.addView(hc);
}
Then nothing shows. HeroCard is a custom view that just implements the onDraw and the onCreate(Context context) methods (I won't copy the code as it's just that).
My guess is that Button is implementing a function that I'm not and that is why it is not drawing.
Any idea?
Thank you very much!
Upvotes: 0
Views: 312
Reputation: 4377
Use this:
hc.setWidth(200);
hc.setHeight(50);
In:
for (int i = 0; i < 8; i++){
HeroCard hc = new HeroCard(this);
HandLayout.addView(hc);
}
And check the output.
Upvotes: 1
Reputation: 1287
Seems like you are not setting any params to your HeroCard
view, it has no size, try to recover the params with getLayoutParams()
and modify the width
Upvotes: 1