Is it possible to have another layout in my main layout? - android

Is it possible to have another layout in my main layout?
Such that i can set my imageview in another layout.

You can create a child layout from your Java code and then use addView() method.
For example:
LinearLayout l = new LinearLayout(this);
l.addView(new LinearLayout(this));

Sure, take a look at this blogpost.
http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html

Related

Different layoutparams for different views

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.

edit layout of existing child in RelativeLayout

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);

How to hide framelayout dynamically in android

I want to hide framelayout dynmically in android, How I can achieve this.
provide an id attribute to your frameLayout by defining it in xml file as:
android:id="#+id/someID"
and in code, write following:
FrameLayout layout = (FrameLayout)findViewById(R.id.someID);
layout.setVisibility(View.GONE);
You can also use
View.INVISIBLE
which means the element will be still there.
Change the visibility like this:
FrameLayout layout = (FrameLayout) findViewById (R.id.your_id);
layout.setVisibility (View.GONE); // or View.INVISIBLE, depending on what you exactly want
You can hide or show views using setVisibility(int).

How to set two layout one at top and anther at bottom

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);

Can I add views to a scrollview without inflating/re-inflating layouts?

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);

Categories

Resources