I have a LinearLayout with a ScrollView inside and a checkbox underneath the scrollview. Whenever i put alot of text in the scrollview, it will expand through the whole screen and kick out the bottom checkbox view. How do i prevent that from happening?
Basically, i want the checkbox to always be right underneath the scrollview. I also want the scrollview to shrink and expand depending on its text. When theres alot of text inside, it should expand to the point where the checkbox is still visible at the bottom of the screen.
It should look like this:
Where the filled ScrollView should have a scroller if the text is too much, rather than kicking out the checkbox from the screen
Help!
My layout looks like:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- TextView inside --->
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:gravity="top"
android:orientation="horizontal" >
<!-- CheckBox inside --->
</RelativeLayout>
</LinearLayout>
Dont worry about the syntax, or all the stuff that are inside, I wrote this quick because the code inside is really long and unnecessary!
Try this layout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<!-- TextView inside --->
</ScrollView>
<!-- CheckBox Here --->
</LinearLayout>
Let's start simple. Try replacing your parent LinearLayout with a RelativeLayout. If this doesn't work, you may have to fix the height of ScrollView to some fixed height using weight, or pixels (which is non-ideal):
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- TextView inside --->
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:gravity="top"
android:orientation="horizontal" >
<!-- Stuff inside --->
</RelativeLayout>
</RelativeLayout>
Define a fixed size to your ScrollView. As bigger as the text becomes, the scroll is defined to that size (like layout_height="100dp")
UPDATE
Try something like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="200dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- TextView's inside - -->
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- CheckBox's inside - -->
</LinearLayout>
</LinearLayout>
Related
I have an Activity with 2 LinearLayouts vertical in the screen and 1-2 buttons in the bottom right corner.
Depending on the length of the LinearLayouts it could happen that the text in the Layouts is hidden from the Button. Hence i would like to make the Activity always scrollable that the User is able to drag the LinearLayouts a bit up and read the text.
Here is a little Visualization:
I tried it with some solutions i found on the web but its not working:
first try:
<ConstraintLayout>
<LinearLayout>...</LinearLayout>
<LinearLayout>...</LinearLayout>
<Button>...</Button>
<ConstraintLayout>
second try:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout>...</LinearLayout>
<LinearLayout>...</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button .... />
</RelativeLayout>
</RelativeLayout>
Try to add Padding Bottom
<LinearLayout
android:padding_bottom="50dp"
/>
So I have a ExpandableListView in my layout, but for some reason It is showing only some part of it when I run the app. Yes, it's "some" part - actually almost the enture first GroupView.
If I set a fixed height to the list at android:layout_height="some dp", instead of android:layout_height="match_parent" I can see the whole list. But, If I have too many group view's and child view's, again, I can see only some part of it (as the height is fixed).
I've tried to put the expandable list inside a LinearLayout, have tried to set android:layout_height="wrap_content", and so on, but without success.
How can I solve this?
Thank you,
<?xml version="1.0" encoding="utf-8"?>
<!-- That's the main layout.-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view_m"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout is here because a ScrollView can only have one child view.-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- That's the second ScrollView. But this one is horizontal.-->
<HorizontalScrollView
android:id="#+id/map_layout"
android:layout_width="match_parent"
android:layout_height="400dp">
<!-- This LinearLayout is here because a ScrollView can only have one child view.-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!-- Some view's here -->
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="#+id/scroll_down"
android:text="Scroll down to see marker info!"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/holo_green_light"
android:background="#android:color/black"/>
<ExpandableListView
android:id="#+id/m_expandable_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ExpandableListView>
</LinearLayout>
</ScrollView>
I have a FrameLayout with many children. One of the children is a LinearLayout. I want the width of the LinearLayout to match_parent but about 90% so; which means I want to add some sort of paddingLeft/Right or margingLeft/Right. But when I add the padding or margin, it is not applied in the Graphical Layout. How do I do this correctly?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="#color/red"
android:marginLeft="20dp"
android:marginRight="20dp"
android:orientation="vertical" >
....
you have
android:marginLeft="20dp"
android:marginRight="20dp"
instead change it to:
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
If it still doesnot work, put this layout inside another layout and set the margins to the other layout.
You worte following code, which is not correct
android:marginLeft="20dp"
android:marginRight="20dp"
Try This :-
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
**android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"**
android:background="#android:color/white"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
Similarly you can give margin at Top and Bottom
I have a vertical ScrollView with some ImageViews that I can scroll up and down. At the bottom of my application I have a footer consisting of a LinearLayout with a partly transparent background image (png). How do I achieve the following behavior?
Consider the following layout
<LinearLayout blah blah... >
<RelativeLayout
android:id="#+id/guesses_scroll_view_holder"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/guesses_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bgrepeat"
android:scrollbarStyle="outsideOverlay"
android:layout_above="#+id/footer" >
<LinearLayout
android:id="#+id/guesses"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bgrepeat"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/peg_picker_bgrepeat"
android:orientation="vertical" >
< some footer content />
</LinearLayout>
</RelativeLayout></LinearLayout>
What I got at the moment is something that looks like this
Since my background image peg_picker_bgrepeat is not rectangular, I get an ugly border above the ScrollView. How can I make the contents "scroll behind" the footer?
I have a scrollview with a linear layout inside. One of the elements inside this linearlayout is a glsurfaceview.
This all works correctly and when I scroll the glsurfaceview moves up and down however when the glsurfaceview reaches the top or bottom of where it should of the scrollview where it should be clipped it is not and is continued outside of the scrollview. This screenshot should make it clearer:
Don't think it's completly nessecary but here is my layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dip"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
>
<!-- LOTS OF SEEKBARS/TEXTVIEWS -->
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.4"
android:layout_marginRight="10dip"
android:layout_marginLeft="10dip"
android:orientation="horizontal" >
<android.opengl.GLSurfaceView android:id="#+id/glview"
android:layout_width="100px"
android:layout_height="250px"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<!-- OK/CANCEL BUTTONS -->
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
All help much appreciated :)
Hosting SurfaceViews inside ScrollView (or Listview, etc.) is currently not supported.
You may use below lines for removing over scrolling :
glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
glView.setZOrderOnTop(true);
glView.setZOrderMediaOverlay(true);
And for removing black background :
linearLayout.setBackgroundColor(context.getResources().getColor(R.color.white));
linearLayout.addView(glView);
Also add below line in your manifests file :
android:hardwareAccelerated="true"
It is not about support as answered abowe. The cause of issue is that GLSurfaceView is not on the view level. In short: for you case you have GLSurfaceView at the first level, then other views with holes in views abowe GLSurfaceView (this handles by windows manager, and it dosent matter where you put GLSurfaceView on xml, it will be on first level in any case and others views on next level)
So, what you need is to force view update, and there is work around: you should put scroll with GLSurfaceView or (RecyclerView with GLSurfaceViews) "between" two FrameLayouts. something like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
---- here should be linear layout with your glView, or RecyclerView instead if required ----
</ScrollView>
--- this frame also required: ---
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
</FrameLayout>