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
65
votes
6 answers

How to split the screen with two equal LinearLayouts?

Wanna to split a screen for my app with two LinearLayouts. What parameters should I use to make exact splitting in two equal parts - first LinearLayout on the top and the second one is just under it.
Eugene
  • 59,186
  • 91
  • 226
  • 333
62
votes
1 answer

Android empty Linear layout contents

H have multiple TextViews inside an LinearLayout. Now I want to delete this text view in java. The views are generated dynamically. How can I empty all contents inside this LinearLayout?
Manoharan
  • 725
  • 1
  • 7
  • 12
62
votes
2 answers

How to add a fragment to a programmatically generated layout?

I have the following code working which generates fragments, but only if I am adding them to a linear layout which exists in my XML file. LinearLayout fragmentsLayout = (LinearLayout)…
Zapnologica
  • 22,170
  • 44
  • 158
  • 253
61
votes
6 answers

Setting a maximum width on a ViewGroup

How do I set the maximum width of a ViewGroup? I am using a Theme.Dialog activity, however, this does not look so good when resized to bigger screens, it's also sort of lightweight and I don't want it taking up the whole screen. I tried this…
zsniperx
  • 2,732
  • 6
  • 25
  • 32
59
votes
7 answers

Change background of LinearLayout in Android

I am working on an Android application. I want to change the background of a LinearLayout element. What attribute can I set in order to change its background?
Durga
  • 1,191
  • 1
  • 12
  • 18
56
votes
6 answers

Adding a view to a LinearLayout at a specified position

I have the following main.xml file with a LinearLayout
Joeblackdev
  • 7,217
  • 24
  • 69
  • 106
55
votes
14 answers

How to center a textview inside a linearlayout

I have the following layout i'd like to make the textview appear in the center and middle of the view. How can i acheive this? I've tried adjusting the various gravity attributes when looking at the layout in graphical view, but nothing seems to…
turtleboy
  • 8,210
  • 27
  • 100
  • 199
52
votes
10 answers

android:layout_height 50% of the screen size

I just implemented a ListView inside a LinearLayout, but I need to define the height of the LinearLayout (it has to be 50% of the screen height).
52
votes
2 answers

How to group multiple views in a ConstraintLayout

I have added 3 buttons in a ConstraintLayout. I have added a button to disable or enable these buttons. If I was using normal LinearLayout. I could have put all the buttons in a Linear Layout and enable or disable that particular layout. But I am…
52
votes
1 answer

Custom Widget using LinearLayout not getting onDraw()

I'm creating a custom widget by extending LinearLayout: public class MyWidget extends LinearLayout { private static Paint PAINT = new Paint(Paint.ANTI_ALIAS_FLAG); static { PAINT.setColor(Color.RED); } public…
Steve Pomeroy
  • 10,071
  • 6
  • 34
  • 37
50
votes
6 answers

Android Fragment does not respect match_parent as height

Sorry for the huge code dump, but I'm truly lost. MyActivity.java onCreate: super.onCreate(savedInstanceState); setContentView(R.layout.activity_singlepane_empty); mFragment = new PlacesFragment(); getSupportFragmentManager().beginTransaction() …
49
votes
10 answers

Set two buttons to same width regardless of screen size?

Ok, i have two buttons in linear layout:
46
votes
2 answers

How to set Ripple effect on a LinearLayout programmatically?

I want to set the background android.R.attr.selectableItemBackground to a LinearLayout. When using XML there are no problems (it works)
Splact
  • 702
  • 2
  • 8
  • 15
46
votes
1 answer

Android LinearLayout fill-the-middle

I have a vertical, set height (300px) LinearLayout (LL) with 3 nested LLs. 1 and 3rd are set with android:layout_height="wrap_content" and the middle one with android:layout_height="fill_parent". To my dismay, 3rd LL gets pushed out with 2nd one…
Bostone
  • 36,858
  • 39
  • 167
  • 227
43
votes
4 answers

selected item on custom listview with contextual action bar

I recently started using android actionbars and contextual action bars (CAB). I have just one activity which is a ListActivity. Basically I use the following code snipped to "activate" the CAB: ListView listView =…
Domi
  • 1,451
  • 2
  • 13
  • 25