I have a RelativeLayout with a number of children. The RelativeLayout is the main layout of my activity. I need to add to one of the children the layout value layout_alignParentBottom="true". I need to do this programmatically. the link How to set the android property layout_alignParentBottom to a button dynamically is not working for me because, basically, I don't want to have to inflate the RelativeLayout as I already have it at the setContentView(...). Any ideas how to do this?
I figured it out:
RelativeLayout.LayoutParams layout = (LayoutParams) theChild.getLayoutParams();
layout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
Related
Is it possible to set one LayoutParams to RelativeLayout(it is inside another Layout) and set another ones to a view that is in this Layout.
RelativeLayout inside which another Relative Layout with some LayoutParams and inside 2nd Reltive layout a view with another LayoutParams
Is situation like possible?
try by,
1.giving id to each views you wanna resize
2.initialising those ids to a member variable
3.setting the layoutparams using setLayoutParams(left,top,right,bottom) method.
Parent_LinearLayout
LinearLayout
TextView
LinearLayout
I have a parent Linear layout in the XML.
I created a Linear layout dynamically and whose child are TextView and A linear layout.
I added this layout to the Parent linear layout.
Now my question is how to get the Tag of Linear Layout(4th) and the Tag of its child (which i will add later dynamically).
for(int i=0;i<parent_Layout.getChildCount();i++){
View v=parent_Layout.getChildAt(i);
Toast.makeText(getApplicationContext(),""+parent_Layout.getChildCount() , Toast.LENGTH_LONG).show();
}
am trying to do something like this, but am not getting any idea how to achieve this
You can use something like setTag() on layouts...and later retrieve the layout using getTag().Hope that helps.
hi I have 2 layout inside a framelayout and i want one linearlayout at top and another at bottom where i will specify height for both the layouts
and how to set this parameter for the linearLayout "layout_gravity " by code not by XML
Use a surfaceView , the SurfaceView allows you to stack in the Z order.
Docs
make sure your surfaceView is under the views of the views you want to stack.
Hope this helps
first fetch the layout from id.
LinearLayout layout = (LinearLayout)findViewById(R.id.IDOFLAYOUT);
//the set the gravity by this method
layout.setGravity(Gravity.CENTER);
It is possible to add views to LinearLayout one after another in upward direction?
You can add it programmatically with:
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.addView(newView, index);
You just have to add always with index = 0
Is this the answer to your question?
If you want to add views to LinearLayout in upward direction(i.e. from bottom to up) use
android:gravity="bottom"
property in the xml of LinearLayout and then add views in the layout.
Hope this will solve your problem.
If you want to keep your views top, relativelayout is another choice.
I would like to take an existing ScrollView with a view in it, and add more views, dynamically (at runtime) to the ScrollView container.
Is it possible to add these views without having to create a new layout and inflate it? If so, what's the general process for adding these views dynamically?
For the sake of this question, assume the views are TextView...
Thanks!
A ScrollView can only have one child, so it doesn't make sense to add more children to it directly. Lets say your ScrollView has a LinearLayout inside of it, then you can add more views to the LinearLayout:
LinearLayout layout = findViewById(R.id.my_linear_layout);
TextView textView = new TextView(this);
layout.addView(textView);