A ViewGroup is a special view that can contain other views, called children. The view group is the base class for layouts and views containers
Questions tagged [android-viewgroup]
223 questions
1
vote
1 answer
Using a ViewGroup as a list?
In some situations, it is better to use a ViewGroup to create lists, acting as something similar to a ListView, or RecyclerView.
For example, I have a situation where I need to display a list of items in a ViewGroup which is a child of the root…

Farbod Salamat-Zadeh
- 19,687
- 20
- 75
- 125
1
vote
0 answers
getIdentifier() or getChildAt()! Which of the two is more efficient to access button/view when loop's big and how?
Scenario:
My Activity contains a few buttons with ID: btn1, btn2 and so on. I want the code to access these buttons through loop counter. So, which of the below two approaches is more efficient? Thanks!
getChildAt():
for (int optionCounter = 0;…

Johnny
- 282
- 1
- 15
1
vote
1 answer
removeView (view) not working in subclass of ViewGroup
I have a MyLinearLayout subclass extends ViewGroup which make Views inside it auto-wrap.
public class MyLinearLayout extends ViewGroup {
private final int cellHeight = 70;
public MyLinearLayout (Context context, AttributeSet attrs) {
…

TRX
- 465
- 1
- 8
- 17
1
vote
0 answers
Galaxy S5 ignoring relativeLayout padding - views cutting off
I have a relative layout with 16dp padding that contains (among other things) a button with the following dimensions:

Kurian Vithayathil
- 807
- 2
- 7
- 20
1
vote
1 answer
Android(MeasureSpec): When Is it possible to get both height and width as "MeasureSpec.UNSPECIFIED"
I am programming my own layout, extending the ViewGroup class. One of the meethod you need to override is the onMeasure() method. In this method, the parent View (the view that will contain my layout) will pass the posible width and height my…
user2930576
1
vote
1 answer
Layout Inflater, ViewGroup and removeView()
I am wondering if someone can explain to me why, when inflating a layout, if a ViewGroup is specified that a later removeView() does nothing. That is:
in onCreate:
currentView = this.findViewById(android.R.id.content).getRootView();
vg =…

TrustNoOne
- 585
- 1
- 5
- 15
1
vote
1 answer
BadgeView and SlidingTabStrip clicking error
i am using sliding tab from:
https://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html
and BadgeView from:
https://github.com/jgilfelt/android-viewbadger
i just add these lines of code to…

mmlooloo
- 18,937
- 5
- 45
- 64
1
vote
0 answers
Changing the Background of a Specific Preference Item is not working
I have a preference, to be used as settings of my application. I want to change the background color of a particular item in listpref (listview). I used the code below:
Drawable background =…

pkverma
- 21
- 4
1
vote
3 answers
Android - How to convert DP to PX - density independent to absolute pixels
I have a situation wherein I need to add layouts at runtime as follows:
1. A Button layout is already defined in XML:
2. When the user clicks the Button, an EditText and another Button are dynamically added to the existing layout:
It works…

Yash Sampat
- 30,051
- 12
- 94
- 120
0
votes
0 answers
dispatchTouchEvent() is not working in case of dialog and menu
I am trying to perform programmatically click using view.
I am able to achieve this on normal UI if it is a button or a text or a list.
Here is my code:
element.GetView().getRootView().dispatchTouchEvent(mMotionEvent);
this is working fine in case…

kishan verma
- 984
- 15
- 17
0
votes
1 answer
How to resolve reference: ViewGroup in MPAndroidChart
I'm trying to run this MPAndroidChart PieChart example, but getting the error:
Unresolved reference: ViewGroup
LayOutParams() shows Viewgroup as accepted input, but won't accept it. Am I right in understanding that the sizes a LinearLayout to the…

nextural
- 51
- 5
0
votes
0 answers
How to group items within RecyclerView when using FlexboxLayoutManager
I am making a simple quiz-like app where the player needs to guess a set of words based on some clues. The placeholder for the words is managed using a RecyclerView where each item corresponds to one letter of the hidden words. I am using…

BuddhaBowl
- 1
- 1
0
votes
0 answers
What is the correct way and place to get parent view's width and height from within a custom view?
My custom view extends the AppCompatImageView class and it needs to know its parent view's dimensions. The following code is used:
val w = (parent as ViewGroup).width
val h = (parent as ViewGroup).height
The problem:
I am not sure where to…

Crocodile
- 5,724
- 11
- 41
- 67
0
votes
0 answers
How to render Video on Software Layer in Android
I have a use-case where I need to draw some paths on Android Canvas of a ViewGroup in a ViewGroup whose hierarchy also contains a Video.
As per https://developer.android.com/topic/performance/hardware-accel#scaling , there are problems with scaling…

Sourabh
- 545
- 5
- 12
0
votes
0 answers
Apply "draw" method code to views from style
I want to set a watermark to certain views (mostly viewgroups) of my app.
I managed to create the watermark with some canvas redrawing within the onDraw() method, but to apply my demo I needed to create a sublass of FragmentLayout in order to…

htafoya
- 18,261
- 11
- 80
- 104