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

Position of buttons in LinearLayout

I've added 5 buttons (see below), I need that reset button should be equally align as that of the above two buttons in order to maintain uniformity. Also I am not able to align submit button exact below of GoodButton.
-1
votes
2 answers

layout_weight: Text is not displayed

I was trying to make an interface that allows horizontal texts to be equally space, using layout_weight for responsiveness So, I tried the code…
-1
votes
2 answers

The method startActivityForResult(Intent, int) is undefined for the type ABC

i have a class ABC with implements Serializable ABC class is an alarm class so using bunch of functions, i just wanted to upload image from SD card, to that i need to view images in GRIDVIEW then user need to select the IMAGE, this is the process i…
-1
votes
2 answers

How to add buttons with for loops to a layer in Android

I'd like to create lots of buttons with constant width and height on demand. How do do the following in android? for(row =0; row*buttonSizeY
-1
votes
2 answers

How to place textviews center with near imageview and textview android?

Hi I want to achieve the desired output similar to screenshot attached below. a view line separation where I need to place textview at center and near to the textview an image and text for size and color. How to achieve it? My code is as follows: I…
-1
votes
1 answer

LinearLayout with weight doesn't work inside a listview

I am trying to build a custom view for the ListView rows. Below is what my row looks like Img | Text 1 |------------ Text | Text 2 Below is my layout that I am using to generate row view
-1
votes
1 answer

Four buttons menu using LinearLayout

I`m trying to create a menu that will hold four ImageButtons next to each other and will be relative in size in order to support different screens resolutions. Below the menu I need an additional small image button. Here how it looks in…
-2
votes
2 answers

How to set two RecyclerView of equal size on a screen, keeping height wrap content to avoid white space

I want to set two RecyclerViews on a screen of equal height to cover the screen equally, the problem is, if I use height as wrap_content views don't expand equally, and if I fix their heights or give them layout_weight, than there will be white…
Asad
  • 1,241
  • 3
  • 19
  • 32
-2
votes
1 answer

How to place textview near to Right side of logo android

I have logo (id is tri_logo) which is placed at right side. Near to that, to left of that I need to place version count (id is version_text). But version count is not displaying near to the tri_logo which is right. In simple, I need to place like…
-2
votes
4 answers

Why android layout_weight does not work as expected?

I have two linearlayouts, each occupy the 50% of total space. Inside of them there are different views and I don't understand why the horizontalScrollView1 and the listView1 (look the ids) are not visible. The two views should expand to fill the…
-2
votes
1 answer

The issue about ui

look at the image of my screenshot, and I use the image to state my question. The following is my code of layout:
Json zhang
  • 119
  • 14
-2
votes
2 answers

Views in Linear Layout not getting equal space with android:layout_weight attribute

As describe in the topic's title, I have 3 TextView and I would like them to share the whole screen's width using the android:layout_weight attribute, but doing so didn't get the sought results. LinearLayout:
Cris
  • 2,002
  • 4
  • 30
  • 51
-2
votes
2 answers

How to implement Google Like Card View

I wonder how to implement Card View layout like in the google tutorial, in tutorial there is only simple card view, but how to get such result ? https://developer.android.com/design/material/images/card_travel.png I can implement this, but I need to…
-2
votes
2 answers

layout_weight in LinearLayout not working - tried everything

layout_weight in LinearLayout is driving me nuts. I've read reams of similar question on StackOverflow and the web but none address my problem. I've copied multiple samples I've encountered but still no joy. My layout (below) is very simple I've…
-3
votes
2 answers

Space in the layout even after distributing weight

Why there is spaces in the bottom part of the android it was supposed to cover up all the spaces by distributed weight
1 2 3
30
31