I have linear layout but bottom part not display if scrolling data is more then screen size.
Streaching Bottom Part when Using Scrollview inside the linearlayout, when scrolling data more then height of the device height.
If i have less data then vertical screen size then all button of bottom appears correctly.
public class TestGUI extends LinearLayout {
sv = new ScrollView(context);
hsv = new HorizontalScrollView(context);
this.addView(topLinearHorizonal);
hsv.addView(tableLayout);
sv.addView(hsv);
this.addView(sv);
this.addView(fullbottomLinearHorizonal);
}
Edited:
LinearLayout fullbottomLinearHorizonal= new LinearLayout(context);
fullbottomLinearHorizonal.setOrientation(VERTICAL);
fullbottomLinearHorizonal.addView(clearLinearHorizonal);
fullbottomLinearHorizonal.addView(bottomLinearHorizonal);
If you want to show fullbottomLinearHorizonal always at the bottom(visible) you can try below while adding views to TestGUI:
LinearLayout.LayoutParams svParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1);
this.addView(sv, svParams);
LinearLayout.LayoutParams fullbottomParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, WRAP_CONTENT);
this.addView(fullbottomLinearHorizonal, fullbottomParams);
Edit: Also default orientation for LinearLayout is horizontal. See link.
You should better set it vertical at TestGUI:
this.setOrientation(VERTICAL);
If you want fullbottomLinearHorizonal at the end of the scroll content then you must add it inside of the scrollView.
Related
I have a header layout that programmatically needs to be divided into 3 equally sized layouts. I tried weights, but nothing showed up, so I hardcoded the height in there and the root layout (extra header) becomes bigger. So they are working but the background color I have assigned them to doesn't show up, the button that is supposed to show inside the right layout doesn't show up and when I use weights instead of hardcoded numbers, the layouts are also not visible. Am I missing something?
private void SetHeader(LinearLayout extraHeader)
{
ImageView btnSettings = new ImageView(this);
btnSettings.SetBackgroundResource(Resource.Drawable.general_btn_dots_horizontal);
btnSettings.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
LinearLayout lnLeft = new LinearLayout(this);
LinearLayout lnCenter = new LinearLayout(this);
LinearLayout lnRight = new LinearLayout(this);
extraHeader.Orientation = Orientation.Horizontal;
LinearLayout.LayoutParams lpWeights = new LinearLayout.LayoutParams(200, 500);
//lpWeights.Weight = 33;
lnLeft.SetGravity(GravityFlags.Center);
lnCenter.SetGravity(GravityFlags.Center);
lnRight.SetGravity(GravityFlags.Center);
lnLeft.SetBackgroundColor(Android.Graphics.Color.ParseColor("#222222"));
lnCenter.SetBackgroundColor(Android.Graphics.Color.ParseColor("#333333"));
lnRight.SetBackgroundColor(Android.Graphics.Color.ParseColor("#444444"));
lnLeft.LayoutParameters = lpWeights;
lnCenter.LayoutParameters = lpWeights;
lnRight.LayoutParameters = lpWeights;
lnRight.AddView(btnSettings);
extraHeader.AddView(lnLeft);
extraHeader.AddView(lnCenter);
extraHeader.AddView(lnRight);
}
Also: Making the extra header orientation vertical shows my layouts right... only on top of one another and not side by side...
Remember folks: If the layout already has children (i.e.: from the xml) REMOVEALLVIEWS()
I have an issue with ScrollView which seems to add a top margin for its child. I have a LinearLayout above it, which sets Top margin in order for the layout to be below other elements (its parent is FrameLayout), then ScrollView is inserted into the LinearLayout, and a finally a child is attached to ScrollView.
The following image shows empty space that appears between "border" and order details (TextView):
Image
Java Code:
// Inner layout to accommodate ScrollView
LinearLayout inner_layout = new LinearLayout(app.getApplicationContext());
LinearLayout.LayoutParams inner_params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 440);
inner_params.setMargins(0, 135, 0, 0);
inner_layout.setLayoutParams(inner_params);
// ScrollView for details of the order (in case everything doesn't fit in the body)
ScrollView scrollView = new ScrollView(app.getApplicationContext());
params_in = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
scrollView.setLayoutParams(params_in);
scrollView.setFillViewport(false);
TextView body_text = new TextView(app.getApplicationContext());
params_in = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params_in.setMargins(10, 0, 10, 10);
body_text.setLayoutParams(params_in);
body_text.setTextColor(getResources().getColor(R.color.colorTextSecondary, null));
It's almost as if top margin of 135 is also used for ScrollView's child.
If someone could help understand what I'm doing wrong I would appreciate it a lot.
Could some help me with Layouts? I'm having a problem getting it to display the way I'd like.
I have two relativelayouts in a linearlayout. RelativeLayout 1 is used to accomodate a fragment, RelativeLayout 2 contains the 'main' layout that should fill the screen when there is no fragment, but resize when the fragment is added.
I create the layouts dynamically like so:
LinearLayout mainLayout = new LinearLayout(this);
mainLayout.setLayoutDirection(LinearLayout.VERTICAL);
unityPlayerLayout = new RelativeLayout(this);
youtubeLayout = new RelativeLayout(this);
LinearLayout.LayoutParams mainParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
mainLayout.setLayoutParams(mainParams);
RelativeLayout.LayoutParams youtubeLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,600);
RelativeLayout.LayoutParams unityPlayerLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.MATCH_PARENT);
unityPlayerLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
mainLayout.addView(youtubeLayout,0,youtubeLayoutParams);
mainLayout.addView(unityPlayerLayout);
unityPlayerLayout.addView(playerView,0,unityPlayerLayoutParams);
Upon adding the fragment, unityPlayerLayout does not resize and aligned to the bottom though. It get's pushed to the right, I can see a sliver of a couple of pixels, which is weird, since youtubeLayout and mainLayout should match the screen.
So, to summarize: Upon adding a fragment to youtubeLayout, I need unityPlayerLayout to resize it's height and drop to the bottom, but in practice unityPlayerLayout gets pushed to the right, and does not resize it's height.
Anyone any idea? Much appreciated!
You nee to set Layout orientation for the main LinearLayout, not direction
Change
mainLayout.setLayoutDirection(LinearLayout.VERTICAL);
to
mainLayout.setOrientation(LinearLayout.VERTICAL);
// try this way,hope this will help you...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout mainLayout = new LinearLayout(this);
RelativeLayout unityPlayerLayout = new RelativeLayout(this);
unityPlayerLayout.setBackgroundColor(getResources().getColor(android.R.color.holo_red_dark));
RelativeLayout youtubeLayout = new RelativeLayout(this);
youtubeLayout.setBackgroundColor(getResources().getColor(android.R.color.holo_red_light));
mainLayout.setOrientation(LinearLayout.VERTICAL);
mainLayout.addView(youtubeLayout,new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,600));
mainLayout.addView(unityPlayerLayout,new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,0,1f));
setContentView(mainLayout,new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));
}
Here is the code that work :
In the code below everything work, but when i try to add a second view it crashes.
public void ClearAllV() {
ImageView IM2 = new ImageView(this);
HorizontalScrollView SW = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
HorizontalScrollView.LayoutParams lp = new HorizontalScrollView.LayoutParams(
HorizontalScrollView.LayoutParams.WRAP_CONTENT,
HorizontalScrollView.LayoutParams.WRAP_CONTENT);
SW.removeAllViews();
IM2.setImageResource(R.drawable.have_fun);
SW.addView(IM2, lp);
}
But if i try to add a second imageview like the one below it crash,
public void ClearAllV() {
ImageView IM2 = new ImageView(this);
ImageView IM3 = new ImageView(this);
HorizontalScrollView SW = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
HorizontalScrollView.LayoutParams lp = new HorizontalScrollView.LayoutParams(
HorizontalScrollView.LayoutParams.WRAP_CONTENT,
HorizontalScrollView.LayoutParams.WRAP_CONTENT);
SW.removeAllViews();
IM3.setImageResource(R.drawable.have_fun);
IM2.setImageResource(R.drawable.have_fun);
SW.addView(IM2, lp);
SW.addView(IM3, lp);
}
The ScrollView and HorizontalScrollView should only hold one child.
Usually you would have a LinearLayout as the only child of the HorizontalScrollView, and add your views to that.
From the ScrollView-documentation:
A ScrollView is a FrameLayout, meaning you should place one child in
it containing the entire contents to scroll;
[...]
A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through
Note that this is about the ScrollView (not the HorizontalScrollView (the hsv doc says the same thing but with horizontal instead of vertical), and thus mentions a vertical layout.
Currently I have a view within another view (its an ad) but because I am using MATCH_PARENT the width is the entire screen length when I only want it to be the ad size. Now WRAP_CONTENT fixes the problem but how do I centre the view on the bottom of the screen now? I was using the following code...
LinearLayout ll = new LinearLayout(this);
ll.setHorizontalGravity(Gravity.CENTER); //Place centre
ll.setVerticalGravity(Gravity.BOTTOM); //place bottom
mobfoxView = new MobFoxView(this, "xxxxxxxxxxxxxxxx", true, true);
mobfoxView.setBannerListener(this);
mobfoxView.setVisibility(View.GONE);
ll.addView(mobfoxView);
this.addContentView(ll, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
problem is that it wont centre anymore because of the WRAP_CONTENT. How do I get this to work so the layout is centred at the bottom of the screen?
Try these edits:
ll.setGravity(Gravity.CENTER | Gravity.BOTTOM);
mobfoxView = new MobFoxView(this, "xxxxxxxxxxxxxxxx", true, true);
mobfoxView.setBannerListener(this);
mobfoxView.setVisibility(View.GONE);
ll.addView(mobfoxView, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
this.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
In this way if ll is appended at the end of the tree it will fill everything and position on the bottom.