I have a nested TableLayout (TableLayout->TableRow->TableLayout->TableRow). The inner TableLayouts have their width set to MATCH_PARENT. It is not expanding to match its parent. See attached screenshots.
EDIT:
I can tweak the width using android:weight and setting the android:layout_width="0dp". I still want to understand this behaviour.
Related
I want to give responsive height to children in a vertical Linearlayout for example(some view height must be 25% of the screen height) I know this is simple if I use weight but the problem is that I have the LinearLayout inside a ScrollView this means I dont know the exact height of the LinearLayout so weight doesn't work here.can anyone give me a way to do so.
Use:
scrollView.setFillViewport(true)
This way, the linear layout inside occupies the full height.
I have an ImageView and I want to set something like this:
min_with=match_parent and max_width=value
does someone know how to do that?
I am guessing your parent is not the root parent and your parent width is not match_parent either.
You can set your parent width as wrap_content and set child width as wrap_content but set child min width to some dp so your child won’t have less width than min width but it will hug the parent on all sides.
You can also take advantage of linear view and its weightSum, weight to childrens
We can go in details if you share more data and small drawing of what you want to do.
I'm struggling with getting LinearLayout to behave like I want it. Unfortunately, both dimension modes MATCH_PARENT and WRAP_CONTENT don't seem to fit for my purposes.
Here's why: I want the child that is added to the LinearLayout to be completely visible. Nothing should be cut off. So normally, I should use WRAP_CONTENT to achieve this behaviour.
But, if there's more space in the LinearLayout than the child really needs, I also want it to fill that space. This is of course what MATCH_PARENT is for.
However, I can't use MATCH_PARENT because in case there is less space in the LinearLayout than my child needs, using MATCH_PARENT will cut off the child which I don't want.
So this leaves me somewhat puzzled as to how I can achieve what I want: How can I allow a child to fill additional space in the LinearLayout (if available) while at the same time forcing the LinearLayout to be at least as big as the child needs in order to be completely visible?
Put your child view inside a ScrollView with width MATCH_PARENT, height MATCH_PARENTand set both the child's dimensions MATCH_PARENT
Instead of using MATCH_PARENT for your child, use WRAP_CONTENT and set your child's weight to 1,So it will take all the empty space in your LinearLayout. Suppose your LinearLayout's height is 128dp, and your child 's height is 56dp, your child will be 128dp . If you set WRAP_CONTENT on your LinearLayout, it will be 56dp, and it child will still take all the place it needs.
If you want your LinearLayout to have a minimum width or height, and not match_parent, you can do setMinimumWidth() or setMinimumHeight() in your xml layout or in your code programmatycally depending your childs default height and width.
I've been trying to achieve this using nested LinearLayouts. Tried setting both width and height to 0dp . But it's not achieving 80% width and height. But it's working when i'm switching it to just single dimension ( ie, just width or height ). Couldn't get any info on it though i googled a lot .
So, now the question : does the Layout Weight work with both dimensions together?.
Note: I cannot use center gravity it , due to the lack of proper width in the children. They need to get it from linearlayout2 ( fill_parent ) .
1、The LinearLayout weight do not work both with width and height, It depends on the orientation of it. the default is Horizontal.
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>