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
4 answers

LinearLayout weightsum not working with image

I have a LinearLayout with weightSum 10 which has 2 child LinearLayout with layout_weight 4 and 6. It works fine when background is color or nothing. But the problem occurs when I set a background image. What can be the problem and solution? Working…
0
votes
2 answers

Equi-height row in table layout

I want to make a re-usable table layout, in which I have 3 rows and last row contains 1 element only whereas first two contains 2 element each. Now, problem is, rows in the table layout are not of equal height despite of giving equal weight to each…
0
votes
1 answer

Misplaced textviews in linear weight based layout

Still quite new to android and such, I was tasked of making a layout that looks exactly like designers sketch. Tried using linear layout and weight, to make sure the elements are in the same place in relation to background no matter the…
0
votes
2 answers

How to make a vertical List of buttons?

I am trying to make a vertical list of 5 buttons which are evenly spaced out it the following format: (Button1) (Button2) (Button3) (Button4) (Button5) Where the buttons are also centered. However I am only getting a blank grey screen. I have…
user3166793
  • 27
  • 2
  • 3
  • 8
0
votes
2 answers

Positioning ScrollView on screen

I would like to position a ScrollView at a certain part of screen independently of the screen size and resolution. E.g. I would like it to take up the bottom 30% of the space. Above this ScrollView I want to have an image and empty space. I have…
0
votes
4 answers

How to create a custom layout using weight?

In order to take all space of the screen I made this layout:
eento
  • 761
  • 4
  • 20
  • 53
0
votes
1 answer

ActionBar title weight won't be applied

I'm currently trying to set the font weight of my ActionBar title to bold, with the following code, but it isn't working as expected. What am i doing wrong?