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

Setting up layout of calculator buttons on android

I have just started learning Android. To start with,I just wanted to create a Calculator application similar to what we get in stock android phones. I used the following layouts: Vertical Layout contining two rows which are: Text view to display…
Rubik
  • 33
  • 1
  • 4
3
votes
9 answers
3
votes
3 answers

android- meaning of layout_weight="0"

I am using layout_weight to specify the ratios of various views in a specific viewGroups in android. From this question's answer I have got clear concept about what layout_weight is. I calculate the size of all viewsin a viewGroup using normal…
Utshaw
  • 4,166
  • 3
  • 20
  • 25
3
votes
7 answers

Understanding android:layout_weight

Why the following listing shows only the second TextView (red)?
3
votes
1 answer

How to fix layout_weight in Linear layout?

In my xml file I set each small circle (ImageView) to be the size of 25% of the screen with a Linear View and layout_weights. Here is a screen shot from my phone (how it is supposed to look) On my tablet it does not change the size to be 25%…
3
votes
1 answer

Android - Using too many linear layouts

Is it a bad practice to use too many linear layouts (20 for example) in a single xml view in android? Does it cause slow rendering for example of the whole view. I sometimes need to use too many weight attributes in a single view that's why i find…
user2469133
  • 1,940
  • 3
  • 21
  • 33
3
votes
0 answers

ScrollView doesn't respect my linearLayout weightSum

When I use the ScrollView some of the columns got fit. Example: DNI column should be a little wider. The reason of using scrollview is because I will add more columns. I tried to change "match_parent" and some trick from other post of…
ecorzo
  • 605
  • 1
  • 6
  • 7
3
votes
2 answers

android : layout_weight not picking values from correct layout on orientation change

I have a LinearLayout which includes a Fragment and a FrameLayout. I want to use layout_weight for them since, I want the Fragment to occupy only a smaller part of the screen whereas as the FrameLayout should occupy a larger part of the screen. I…
3
votes
0 answers

Custom dialog linear layout weight issue

I am using a LinearLayout view with a custom dialog ,when I run the code below, weight is not working correctly as the red view takes the green view's weight and verse vise as image below: but when I use the same layout in another activity , weight…
3
votes
2 answers

Nested Linear Layout Weight

I have one "Master" LinearLayout with several other LinearLayouts nested inside of it that extend all of the way from side to side. I was wondering if I could use weight to split the vertical space up between the nested layouts with the percentage.…
3
votes
5 answers

android layout weight %

I am trying to messing around with the Android layout weight attributes. I want a vertical layout with "3 child layouts" The first will take 25% of the space, the second 50%, and the last 25% of the space. When I try to add to the last layout,…
Ukjent
  • 823
  • 2
  • 9
  • 26
2
votes
1 answer

Android: Trying to set layout weight for CardView using Databinding

I am trying to set the layout_weight to my CardView using below code:
2
votes
1 answer

Android layout_weight iframe and scroll

sorry for my poor english in advance I have a design problem on android studio. I used multiples devices (From version 8 to 10) and it works fine, and one device (version 6) which has a different output (you can check my screens below)wrong display…
2
votes
2 answers

Android widgets is not showing its attributes Suggestions when i going to write

Android Weight is not showing its attributes when I try write its property. But it works if write. Now I want to watch a suggestion when I write. how can I solve this problem? Check image for more…
2
votes
2 answers

ImageView can not be resized using the layout weight

I want to divide my screen into 3 vertically equal parts and add an ImageView to the top part. When I add the image, the parts won't be equal. It can not be changed using layout weight.
shayanmalinda
  • 1,925
  • 3
  • 12
  • 23