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

Android layout using layout_weight, layout_width and maxWidth

I'm trying to get a row of text which will be something like foofoofoo - barbarbar but I want it to ellipse foo and bar if it won't fit on one line. i.e. I'm trying to shorten them down.
Blundell
  • 75,855
  • 30
  • 208
  • 233
5
votes
2 answers

Horizontal android:animateLayoutChanges="true" Animation not smooth

I have a layout that animate as below The txt_billion is shown dynamically, with android:animateLayoutChanges="true" (Layout code below). Notice the Hundred is jumping (actually all are jumping, but the Hundred is just more obvious). How to prevent…
5
votes
2 answers

Why is the same layout_weight leading to different widths for Android ImageButton and Button?

I'm getting some weird behavior in my LinearLayout when I try to set regular Buttons and an ImageButton to the same layout_weight. The image button's android:src resource is extrememly small and fits well inside the ImageButton without any problems.…
5
votes
6 answers

SetSelection on a spinner crashes when layout_weight is assigned to spinner

I have done a simplified experiment to identify where I am having this problem. It was a long question with a lot of code earlier. Now I have kept a small and simple code: protected void onCreate(Bundle savedInstanceState) { …
suku
  • 10,507
  • 16
  • 75
  • 120
5
votes
0 answers

Custom view (extending LinearLayout) "losing weight" property

So.. I am defining a custom view / layout that looks like follows:
5
votes
5 answers
5
votes
4 answers

How to get height in pixels of LinearLayout with layout_weight

this is my first post. I am learning to code in java for android apps. I am using a LinearLayout "variable named: ll" with a predefined layout_weight (which I want to change whenever I want in the future) and height and width set to MATCH_PARENT. I…
Usman
  • 2,331
  • 2
  • 21
  • 29
4
votes
1 answer

How to align in a row an icon to the end of an edge?

In my Kotlin Android App project I have Rows with Text and an Icon. The Icon right of Text shall be aligned to the end edge. The Text has a Modifier with weight(200.0f), but I do not want to use weight(). When I remove the weight() from text as in…
4
votes
1 answer

Android layout-weight:How to explain the calculation of proportion when width set 'match_parent'

I'm new to android.When learning about the 'weight' property of layout,I got confused. I know that when the layout_width is set to 0dp,each element will occupy weight/weightSum. But when the layout_width is set to match_parrent(perhaps not…
disinuo
  • 75
  • 9
4
votes
3 answers

In a Tabbed Activity with ViewPager, the ListView appears cut from the bottom

I have a Tabbed Activity with three ListView Fragments but the ListView appears cut from the buttom. You never see the last element. I tried everything but I'm not able to solve it. This is the Tabbed Activity: public class TabbedActivity extends…
4
votes
1 answer

Linear Layout - Difference between weight and FILL_PARENT

According to documentaion, FILL_PARENT basically lets the view take up the entire extra space. Weight also dictates how much of the extra space can be taken by the view. What is the difference? For eg: What happens when I use, new…
4
votes
3 answers
4
votes
1 answer

Button's style is adding unknown attribute - Android

I am trying to achieve the look of Facebook's event page and am having trouble copying their three buttons that say if a person is going to an event. I am trying to achieve this, Mine currently looks like this, This is the XML for the buttons …
4
votes
2 answers

Android dynamic screen splitting

What am I trying to do? Activity starts with a ImageView taking the upper 9/10 of the screen, and a ListView the remaining bottom 1/10: As more items added to the ListView, the ratio changes, ListView getting 1/10 more of the screen for each item,…
nobatlinux
  • 347
  • 2
  • 10
4
votes
4 answers

set width and height as percentage in relative layout

I would like to have this: a ViewPager overlaid by 2 arrows And I get what I want by this code. However, I got these warnings of lint : this layout is useless (for dummy layouts) nested weights are bad for performance. I wonder if there is a…
Huy Than
  • 1,538
  • 2
  • 16
  • 31
1 2
3
30 31