Questions tagged [android-layout-weight]

In Android by setting a layout_weight for the Views inside the LinearLayout, the parent layout divides the available space between its children according to their weights.

Description

Indicates how much of the extra space in the LinearLayout will be allocated to the view associated with these LayoutParams.

By setting a layout_weight for the Views inside the LinearLayout, the parent layout divides the available space between its children according to their weights.

Implementation

A Vertical LinearLayout with 2 Views. Top View has layout_weight of 3 and bottom one has 1, which means total of 4. Top View will fill 3/4 of the Layout and bottom one will fill 1/4 of the Layout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <View
        android:id="@+id/view1"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="3"/>

    <View
        android:id="@+id/view2"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"/>    

</LinearLayout>

Link

Android Developers

451 questions
0
votes
1 answer

Android ExpandableList Activity child's android:layout_weight not working

I'm facing a problem that's driving me mad. That's the thing. I have an expandable List Activity wich shows media files. One group are the audio files, the other group are the Image files. AudioGroup's children have one layout, ImageGroup's children…
MBRebaque
  • 359
  • 2
  • 5
  • 14
0
votes
2 answers

android - slide down view weight

I have a linear layout which has 4 childs with different weights. When user click a button at first child , i want to add new child to parent linear layout with different weight ( 0dp height ) . But when i am adding new child all childs height is…
dracula
  • 4,413
  • 6
  • 26
  • 31
0
votes
3 answers

If I use weight layout, then my Java file cannot find the view by id

I have an XML layout using weight layout like this.
Emmy
  • 3,949
  • 5
  • 28
  • 30
0
votes
4 answers

Android layout weight doesn't do anything

I have a LinearLayout with 2 buttons splitting it horizontally. I want those buttons to be at the bottom of the screen, so I added to the layout android:layout_weight="bottom" and nothing changes!
aclowkay
  • 3,577
  • 5
  • 35
  • 66
0
votes
2 answers

Weight setting for a set of three image in a linear horizontal layout

I've a single vertical linear layout with a scrollview inside it. Programmatically I'm adding some thing inside it A TextView, and it's OK: I'm able to center it using LayoutParams params = new LinearLayout.LayoutParams…
realtebo
  • 23,922
  • 37
  • 112
  • 189
0
votes
1 answer

Weight issue with layout

This question is connected with my previous question. I haven't found the solution in correct way - I get screen width programmatically and add margins to ImageView in this way. Now I have new issue. Here is layout where weights are working…
Alex Zaitsev
  • 2,013
  • 4
  • 30
  • 56
0
votes
1 answer

How do layout_weight makes widgets disappear?

I have LinearLayouts nested in a "Master Layout" with their width set to fill_parent and height to 0dp. The Master has a weight sum of 100 and a vertical orientation, and I have the nested layouts with their respective weights. The goal is to split…
0
votes
2 answers

Place View at bottom of a screen/layout using a TableLayout

I am trying to place a TableRow with two Buttons at the bottom of the screen, under other view elements in the layout, but if I put there, the TableRow dissappear out of the screen. I I put at top or in the middle, no problem. I was trying a lot of…
Pelanes
  • 3,451
  • 1
  • 34
  • 32
0
votes
1 answer

Strange layout behaviour - layout_weight and buttons

I have a strange problem concerning a layout in my Android app (I'm learning it, so ofcourse I'm making a calculator :) ). I have specified all the buttons to be 25% of the width of the row, but when I add the EditText at the top, the first column…
Hidde
  • 11,493
  • 8
  • 43
  • 68
0
votes
1 answer

Layout_weight is not working as desired when using a nested LinearLayout

I want to get my LinearLayout to display views in the desired proportion. I have perused some 10 or 15 other questions about LinearLayout and layout_weight, but for some reason no answers seem to apply in my case. I am creating a custom AlertDialog…
-1
votes
1 answer

Is this possible to change weightSum value programatically using setWeightSum(float)?

I am trying to control weightSum for linear layout from fragment. I wondered if it's possible to do that using setWeightSum(float) method. I tried to control weight sum in Linear layout which id is…
user13024999
-1
votes
1 answer

LinearLayout match_parent doesn't take other children's width into account?

I want to create a layout when I have an image, text aligned to the left of the layout. and a chip aligned to the left. I have tried this layout:
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
-1
votes
2 answers

How to design layouts that will only rotate the outer layout not the inner layout?

I have two circle layouts(relative) inner and outer in Frame layout (parent), i need to rotate the outer circle by two finger gesture, but not the inner circle layout, how can i achieve this.Like in below picture , outer circle will only rotate with…
-1
votes
1 answer

how is more efficient to center a view in a vertical linear layout?

I have a vertical linear layout with a 2 views inside. how can i center this view vertically? what's the most cost efficient 1) replace the linear layout with relative layout and use android:center_toparent= true (expensive as two layout pass on…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
-1
votes
2 answers

android textview layout weight issue

I am working on a project. I am required to make a TextView to be fit into 1 line (as shown below). But after I tried adjusting layout_weight, it fails. Here is my code (with original layout_weight):
hycwong
  • 13
  • 1
  • 6