Horizontal Scroll View Width in Android?
How can I set a width for Horizontal 开发者_JAVA百科Scroll View?
myHorizontalScrollView.setWidth();
This doesnt appear to work, I need to limit the scroll views width.
ViewGroup.LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT
,LayoutParams.FILL_PARENT);
myHScrollView.setLayoutParams(lp);
You can set the width and height using the layout parameters object.
To set exact number as width you need to use the TypedValue class
int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
(float) 200, getResources().getDisplayMetrics());
And the int should be set in the LayoutParams constructor.
ViewGroup.LayoutParams lp = new LayoutParams(width ,height);
myHScrollView.setLayoutParams(lp);
Also you can set width and height to wrap_content
and fill_parent
Set your scrollview to fill the parent's width and make that parent 200dp wide
精彩评论