Hello,
I have this problem where a scrollable layout (one that resides within
a HorizontalScrollView) is scrollable if I put it in a LinearLayout,
but NOT scrollable if I put it in a TableLayout. I'll demonstrate with
code.
In the code below (all code resides within the onCreate method of my
activity), I create a LinearLayout containing two buttons. Due to the
buttons size, the layout is too wide, and doesn't fit on screen.
Therefore, I wrap it in a HorizontalScrollView.
/*
-------------------------------------------------------------------------------------------------
*/
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
ll.setOrientation(LinearLayout.HORIZONTAL);
for(int j = 0; j < 2; j++) {
Button button = new Button(this);
button.setText("text");
button.setWidth(200);
ll.addView(button);
}
ll.setBackgroundResource(R.drawable.border);
HorizontalScrollView hsv = new HorizontalScrollView(this);
hsv.setFillViewport(true);
hsv.addView(ll);
/*
-------------------------------------------------------------------------------------------------
*/
Now, In the code below, I put my scrollable layout into another
LinearLayout (I want to add other, non-scrollable Views later). This
does what I want it to: the first layout is too wide, and is therefore
scrollable.
/*
-------------------------------------------------------------------------------------------------
*/
LinearLayout panel = new LinearLayout(this);
panel.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
panel.setOrientation(LinearLayout.VERTICAL);
panel.addView(view);
setContentView(panel);
/*
-------------------------------------------------------------------------------------------------
*/
However, if I instead of the code above use the code below, it doesn't
work. In the code below I put my scrollable layout into a TableLayout.
I expect the same result as above since the first layout is still to
wide for the screen, but I get no scrollbar when using TableLayout.
/*
-------------------------------------------------------------------------------------------------
*/
TableLayout tl = new TableLayout(this);
tl.setStretchAllColumns(true);
tl.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
TableRow tr = new TableRow(this);
tr.addView(view);
tl.addView(tr);
setContentView(panel);
/*
-------------------------------------------------------------------------------------------------
*/
What am I doing wrong? In my application I MUST use TableLayout, and
the cell content MUST be scrollable.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en