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);
Related
I'm inflating views inside a linearlayout dynamically, however once the linear layout reaches the end of the first row, it cuts off the rest and doesn't start on the second row.
for(int a = 0; a < mSkills.get(i).size(); a++){
View singleSkill = LayoutInflater.from(mContext)
.inflate(R.layout.singleskill, holder.mSkillLayout, false);
TextView skillText = singleSkill.findViewById(R.id.singleskilltext);
skillText.setText(mSkills.get(i).get(a));
holder.mSkillLayout.addView(skillText);
}
For the linear layout I have it set to wrap_content for the height:
<LinearLayout
android:id="#+id/ll_skills"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/tv_description"
android:layout_margin="16dp"/>
I've tried setting it to a defined height e.g 300dp however that doesn't work either.
How can I make the layout start on the second row, once the first is full?
Linear Layout can either fill views horizontally or vertically so the 2nd row you are expecting cant to be done with linear layout only. you can try a horizontal scroll view for that to scroll horizontally. For the exact view-like flow that you described, you can use this 3rd party https://github.com/nex3z/FlowLayout
It can manage the flow of your dynamically inflated view such as if there is no space in the first line then it will put the next view in the second line.
also, you can use material design library chips https://material.io/components/chips/#usage
LinearLayout works exactly how it has to be because you specify it as horizontal. For such behavior, you need RecyclerView With GridLayoutManager or create your own layout;).
Actually it's doing exactly as it should be, LinearLayout is Linear!, and place its subviews in a single horizontal or vertical row.
My advice to you is that create dynamic horizontal LinearLayout as you already doing with TextViews. and put every 3 or 4 textviews (depending on screen size) inside it.
and put all LinearLayouts inside one vertical LinearLayout...
Of course in your case, it's not a good idea, the best thing you can do is to use recycler view. but I consider you have problem with that.
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.
How can I achieve this layout?
Use a FrameLayout that act as a parent of a LinearLayout( say layout ll_par) & an ImageView..In your ll_par add your two remaining layout .& remember put the Imageview as the last child of FrameLayout & set its layout_gravity to right|center_vertical & give some margin to your Imageview according to the need ..
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);
Let say that I have an layout in res/values named layout1.xml.
In this layout I have only one linear layout (the black one on the picture)
The thing I want to do is to add an array of linear layouts just like on the picture.
The red ones are linearlayout with horizontal orientation that contains 5 other linear layouts.
I want to do everything in code and I want to set an onclick listener to each of the layouts so when one is clicked I want to hide it. Everything needs to be putted in a function that will return a Layout and the this method should take prams for the rows and cols
public LinearLayout getLayout(int rows,int cols){
return the_layout;
}
You make a LinearLayout with the constructor new LinearLayout(context)
You add layouts with parentLayout.addView(childLayout).
You should be able to do the rest.