Questions tagged [android-linearlayout]

LinearLayout is one of the basic layouts in Android. It arranges its children one after the another, either horizontally or vertically.

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.

All children of a LinearLayout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding). A LinearLayout respects margins between children and the gravity (right, center, or left alignment) of each child. More information about the layout:

4954 questions
43
votes
9 answers

Scale background image to wrap content of layout

I have a layout that contains some text fields and has a background image that's displayed at the top of my activity. I'd like the background image to scale to wrap the content (don't care about aspect ratio). However, the image is larger than…
43
votes
4 answers

Android: ClassCastException when adding a header view to ExpandableListView

I'm trying to add a header to an ExpandableListView like so: headerView = View.inflate(this, R.layout.header, null); expandableListView.addHeaderView(headerView); expandableListView.setAdapter(new SectionedAdapter(this)); Which gives me the…
43
votes
4 answers

Creating LinearLayout Programmatically/Dynamically with Multiple Views

I have a hierarchy that is like this: LinearLayout(horizontal) ImageView LinearLayout(vertical) TextView TextView TextView TextView I want to be able to add the hierarchy above through iteration as long as there is data that could be obtained…
Ernest
  • 431
  • 1
  • 5
  • 5
41
votes
2 answers

combining wrap_content on parent and fill_parent on child

Setting two or more elements of a linear layout the same height seems to be a great problem. I want to set four buttons in a row to the same height. android:layout_height="wrap_content" does it for the moment but when the text on one of the buttons…
nob
  • 1,067
  • 1
  • 11
  • 18
41
votes
7 answers

Change linear layout top margin programmatically android

i have two linear layouts in one frame layout.
user2064024
  • 531
  • 2
  • 7
  • 20
40
votes
17 answers

Android Toolbar moves up when keyboard appears

I'm creating a chat based UI screen where I have toolbar and recyclerview for chat messages, and reply msg layout. Whenever edittext get focus It moves up the toolbar. Instead I would like to resize the recyclerview. some of the stackoverflow…
39
votes
16 answers

ScrollView not scrolling at all

I can't make a ScrollView properly scrolling. It always cut off the content on the bottom, as if it were a normal LinearLayout. My code
thomaus
  • 6,170
  • 8
  • 45
  • 63
38
votes
4 answers

android layout margins with percentage

I want to set margins by percentage.. I have 4 imageviews in a linearlayout and want to set default left,right,top,bottom margins that keep same percentage for each screen size. is it possible ? here is a demo what i want.. And here is what i've…
dracula
  • 4,413
  • 6
  • 26
  • 31
36
votes
5 answers

How to set a different theme to a Layout

I've set a default theme for the whole app. It's defined in styles.xml as follows: I've also defined a dark theme:
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
36
votes
4 answers

how to set onClick method with linearLayout?

I am creating an application and posted a question yesterday how to start activity by click any where on row. Got an idea to do like below but I am getting this error: The method setOnClickListener(View.OnClickListener) in the type View is not…
Smarty Gurl
  • 373
  • 1
  • 3
  • 4
35
votes
3 answers

How to add bottom view to a Coordinator Layout with view pager?

I want to add a bottom view to a Coordinator layout with view pager in it , Bottom View will be on top of fragment loaded by view pager and independent of it . I added a linear layout with layout_gravity = "bottom" but bottom view linear layout is…
35
votes
4 answers

Scrolling with Multiple ListViews for Android

I'm completely stumped on this one. I have three different lists that need to be displayed on the screen. It's completely possible that the lists will extend past the bottom edge of the screen, so I would need scrolling. I've tried using a…
Andrew Burgess
  • 5,300
  • 5
  • 30
  • 37
35
votes
4 answers

Is Android layout really exponentially hard?

Some commonly used android layouts such as RelativeLayout and LinearLayout (when weights are nonzero) have onMeasure() implementations that measure their children twice, resulting in exponential running time when nested. This is easily verifiable by…
Don Hatch
  • 5,041
  • 3
  • 31
  • 48
34
votes
8 answers

TextView Ellipsize (...) not working

I want to have a single lined TextView to show up 3 dots at the end when the text is longer than the TextView. I don't know why - but I don't get it. I already wrapped my head around similar StackOverflow questions, but I ended up with no solution.…
Bins Ich
  • 1,822
  • 6
  • 33
  • 47
32
votes
2 answers

Scrollable layout in Android

I have a registration form in a LinearLayout as shown below: When emulator screen is in it's default position it is working fine. But when I rotate the emulator screen it only displays the elements which are fit to screen and remaining are wrap up.…
Vikas Patidar
  • 42,865
  • 22
  • 93
  • 106