swipeToRefresh.addView(webView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
Basically my webview is added to swipeToRefresh. I try to set the height here to be 1, but my webview still fill the entire screen.
swipeToRefresh is a subclass of SwipeRefreshLayout and is using match_parent in both width and height. Any idea how can I know why the height is not used? How to know why is it changed?
Related
Please consider ImageView inside RelativeLayout it has some specific layout params for RelativeLayout. I need to change the width and height of my ImageView programatically according to the screen size.
How can I save all layout parameters but only change width and height
Following code creates empty layout params but I need to save my old params and change only height and width.
imageViewArticleImage.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mScreenSize.y / 3));
How can I achieve this ?
Use getLayoutParams to get the current layout params. Change the width and height and go from there. IF the view is already visible, call requestLayout to force a new layout pass.
I have a Activity conainting a header with some buttons(See picture).
You can switch the framelayout by clicking on the buttons. I have the framelayout set on wrap_content in the height for making the whole thing scrollable in a scrollview.
But I want to show only a map in the framelayout if you push on button2. And the height of the map need to be FILL_PARENT INSTEAD of WRAP_CONTENT. So I need to change the heigth of the FRAMELAYOUT.
Any ideas how I can do that?
This is what I tried:
ViewGroup.LayoutParams layoutParams = frameLayout.getLayoutParams();
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;//MATCH_PARENT because FILL_PARENT is deprectated
frameLayout.setLayoutParams(layoutParams);
I'm changing the width of a grid view based on its column width and number of columns (which works):
gridView.setLayoutParams(new LinearLayout.LayoutParams(gridManipulation.getColumnWidth() * (int)Math.sqrt(str.length) + 10, LayoutParams.FILL_PARENT));
gridView.setGravity(Gravity.CENTER);
I've tried re-centering it in the parent view but its not working, does anyone know why, its still centred as if it still has the width parameters before my dynamic change.
Set the Gravity as LayoutParams property then set that LayoutParams to your GridView as follows...
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(gridManipulation.getColumnWidth() * (int)Math.sqrt(str.length) + 10, LayoutParams.FILL_PARENT);
params.gravity = Gravity.CENTER;
gridView.setLayoutParams(params);
you cant center it if its bigger than its parent, which is never bigger than the screen, unless you set it manually, which will cause the system to render data outside the screen and slow you way down.....
is it expanding verticaly or horizontally or both? my recomendation would be to put it in a scrollview.
I have an array of Pages, each Page contains content and a specific layout.
I have a Horizontal Pager that can switch between pages when scrolling through them.
My question is, how do I set the width and height of the LinearLayout at runtime so the Page is set properly??
Atm the LinearLayout is set to 1024px width 768px height for landscape mode. This should be changed.
I found out how to do it. Should've read the docs better.
fl.setLayoutParams(new FrameLayout.LayoutParams(width, height));
I have a tableview inside of a scrollview. I want to reserve space for a listview 2/3 of the screen. I am getting the height of the screen, and will divide that in 2/3 and set the height of the ScrollView. But even with manually x and y numbers its blowing up.
App is crashing when I set the ScrollView width and height like this:
ScrollView sv = (ScrollView)findViewById(R.id.usdScroll);
ScrollView.LayoutParams layoutParams = new ScrollView.LayoutParams( -1, 550);
sv.setLayoutParams(layoutParams);
Any ideas what I did wrong?
You can use the layout_weight attribute to specify how much of a view the specific component will use, e.g. android:layout_weight=2. So for your listView set a weight of 1 and a weight of 2 for your tableview, I think. Anyway, play with the weight setting and you can split the view in any ratio you like.
LayoutParams is used to tell their parents how they want to be laid out. So the layout param's type which you set to must match its parent class type exactly.
and here is a better solution, using layout_weight instead. Try this please
<ScrollView android:layout_weight="1" ........></ScrollView>
<ListView android:layout_weight="2" ........></ListView>