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
-1
votes
2 answers

I want to fit 10 to 12 views in a LinearLayout with equal weight distribution

I am learning about TextView and making a birthday list app. I am learning on udacity. I adjusted the weight to 1 and height to 0dp and I thought every TextView would space out equally. Instead only 5 TextViews were able to fit, and when I tried to…
-1
votes
1 answer

Why android:weightSum and android:layout_weight doesn't work with a custom adapter?

I'm populating a ListView with several items using a custom adapter. The way I do it is like this: AdapterDetalleVentas = new adapterDetalleVentas(actDetalleVenta,…
Fabián Romo
  • 319
  • 2
  • 14
-1
votes
1 answer

Images disappear when read more button is clicked?

I created a ScrollView and added two LinearLayouts inside one big LinearLayout and have given weights for those.The problem is that it shows my images of the image slider at initial state and once I clicked read more the images dissapear except for…
Chana
  • 31
  • 2
  • 7
-1
votes
2 answers

LinearLayout children weights

I want to have a LinearLayout with a weight containing another LinearLayout with weight. The problem is, when I try to set weight for children layouts, it gives a warning about bad performance when setting weights to LinearLayout children. I…
-1
votes
5 answers

Android Layout Weight Exactly Twice Of Others

I would like to simply divide a Linear Layout to 3 piece. I did something as in the code below. If I change the weight of second inner layout anything else than 2, it works. But if I change it to 2(two), the second inner layout doesn't appear in the…
-1
votes
3 answers

How to provide proper weight to align the view properly in table android

I am using a heading where I need to place seven headings with correponding values. But the first column has image with two text which is troubling to fit inside the table. I given weight but it's troubling in aligning with other views. Everytime…
-1
votes
2 answers

WeightSum not working as expected in a LinearLayout in android

Well, I have a LinearLayout with two children, an EditText and a Button and they both have a weightSum of 3. All I want is to have a horizontal line with 2 layout_weight EditText and 1 layout_weight Button. Here is my code:
ArgonOne
  • 11
  • 1
  • 9
-1
votes
2 answers
-1
votes
1 answer

How to use weightSum in RelativeLayout

I just Created a Relative Layout with id rl1 What I need I want to create a weightSum with 2 for this relative layout as to put in this layout another 2 relative layout one with id fireID and the other relative layout cartID which each of them take…
user7641488
-1
votes
2 answers

Layout weight not working as intended

I have a slight problem getting my layout_weight to work. I am creating a custom bottomBar. But i cant make it to stretch as i want it to. Bottom Bar View
Jemil Riahi
  • 1,360
  • 5
  • 18
  • 38
-1
votes
1 answer

Linearlayout with weightSum and three layouts

Below is the item of layout i am using in listview.The issue is that when i make visibility of countlayout gone in some items of list I expect vibelayout to be exactly at same place where countlayout was since weigtSum is 3.But it is appearing…
-1
votes
1 answer

Want Buttons to use the full screen in scroll view in android

I want to place 9 buttons in my activity with two conditions: 1.If the screen is small the buttons get scroll. 2.If the screen enough big to fit all of them in one go then they get stretched to fill the screen. I tried but its not working. thanks.…
-1
votes
1 answer

Android - Linear layout weight

This view is a representation of a Calendar. In this layout I have a LineaerLayout inside of an HorizontalScrollView, and inside of LinearLayout they are a lot of TextView. I set min width to TextView, because in portrait position there is not much…
-1
votes
1 answer

Layout weight with two ListViews

I want two set Listviews vertically. I want them to be 40% and 60% length of vertical screen respectively. Here is the code:
Fran
  • 417
  • 2
  • 6
  • 15
-1
votes
1 answer

How to set Weight to make bottom view occupy remaining space Android

I want to model my layout screen in the following 2 parts. Basic Information related Linear layout with expandable view initially 20 % of screen height. Bottom List view occupy Remaining Space. But When the top view is expanded then i want to make…