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>
Related
I'm developing an Android 4 and above application.
One layer generate this Warning:This ScrollView layout or its RelativeLayout parent is possibly useless; transfer the background attribute to the other view
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp" >
<WebView
android:id="#+id/about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layerType="software" />
</ScrollView>
</RelativeLayout>
How can I solve this warning?
This error means that the RelativeLayout is useless, as it only contains one View (the ScrollView). You should make the ScrollView the parent, remembering to move the xmlns:android tag to the ScrollView, as well as the #000 background attribute. This will improve performance and should remove the error. Also remember that a ScrollView should only ever have one subview.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:layout_marginBottom="3dp" >
<WebView
android:id="#+id/about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layerType="software" />
</ScrollView>
Usually, you'd want ScrollView on the outside, which allows you to scroll the content you have.
I think this is what you want:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000"
android:orientation="vertical" >
<WebView
android:id="#+id/about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layerType="software" />
</RelativeLayout>
</ScrollView>
If you really want to use relative or Linear layout you can use ahead of Scrollview provided after linear Layout you will have to use any control(Imageview,Imagebutton etc..) then it will not throw any warning/error.
Happy coding
How can i create the layout like i attached in the background as normal any layout.From that layout when i click any or get back to that layout, the overlay layout should come with any form fields buttons or text ...any
Thanks in advance.
Use RelativeLayout or FrameLayout. The last child view will overlay everything else.
To be sure the overlay view is on top, you can call ViewGroup.bringChildViewToFront() on the relative layout.
Example:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/root_view">
<EditText
android:layout_width="fill_parent"
android:id="#+id/editText1"
android:layout_height="fill_parent">
</EditText>
<EditText
android:layout_width="fill_parent"
android:id="#+id/editText2"
android:layout_height="fill_parent">
<requestFocus></requestFocus>
</EditText>
</FrameLayout>
In this layout, editText2 will cover the editText1
I believe you should use FrameLayout, you can add objects one in front of the other. Please read about it at documentation.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- other actual layout stuff here -->
</LinearLayout>
<LinearLayout
android:id="#+id/overlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" >
</LinearLayout>
</FrameLayout>
Now any view you add under LinearLayout with android:id = "#+id/overlay"
will appear as overlay with gravity = right
hopefully this will help you
I have a linear-layout (vertically-oriented) that contains two nested linear layouts inside of it.
The first linear-layout has a background image that is applied dynamically based on the context o the particular activity. The image pretty much takes up the whole size of the screen
The second linear-layout contains two checkboxes (horizontally-oriented) that should be displayed at the bottom of the activity.
My question is, how can I ensure that the second linear-layout displays at the bottom of the screen and just shows the minimal amount it needs to, allowing the first linear-layout to display as much as its background image as possible? Currently it's being pushed off the screen by the first LL's bg image.
Thank you.
Using Weight you can do what you want:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#FF0000"
android:layout_weight="1"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#00FF00"
android:layout_weight="1"
>
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
</LinearLayout>
</LinearLayout>
You can use RelativeLayout as the outer layout instead of LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
...
</LinearLayout>
<LinearLayout
android:id="#+id/topLayout"
android:layout_above="#id/bottomLayout"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
...
</LinearLayout>
</RelativeLayout>
<LinearLayout
... >
<LinearLayout
...
android:layout_height="0dp"
android:layout_weight="1"
>
...
</LinearLayout>
<LinearLayout
...
android:layout_height="wrap_content"
>
...
</LinearLayout>
</LinearLayout>
Notice on the weighted layout, the height is set to "0dp". With only one weighted, the weighted one will stretch to fit the rest of the available area.
I want to implement this: A ScrollView that contains many elements (ImageViews, TextViews, EditTexts etc) and then after the ScrollView some buttons (which are custom ImageViews) that appear always exactly at the bottom of the screen.
If I use the android:fillViewport="true" attribute, then if the elements of the ScrollView are too big to fit in the screen size the buttons get invisible . If I use the android:Weight=1 attribute then the ScrollView gets only 50% of the Screen when the screen is big and it can fit (I want the buttons to take a small percentage, about 10%). If I set the android:Weight to bigger values then the buttons appear very small.
Please help! Maybe it is something simple that I overlooked but I’ve been banging my head for hours!
Just created and tested it. Looks like you want.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentBottom="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Button1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Button2"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/buttons">
<!--Scrollable content here-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="test text"
android:textSize="40dp"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
<?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="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hallo Welt"
/>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go next page"
android:layout_alignParentRight="true" />
</RelativeLayout>
</LinearLayout>
This worked for me. Give the scroll view a weight of 1. Put all the other widgets following the scroll view in a layout. The scroll view will grow enough to not block the rest.
Widgets in scroll view and rest at bottom
scrollview cannot fit the screen because you put it on a linear layout, so linear layout fit in the screen,
just try to make scrollview as root elemen on xml layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- Here you can put some XML stuff and BOOM! your screen fit to scrollview -->
</LinearLayout>
</ScrollView>
If you do not want to use RelativeLayout, it is better to use LinearLayout. This method is better in my opinion.
Just set the layout_weight to one
Im not very good in creating android layouts so I am not able to align the button to the bottom in the MainView.
Picture:
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
<ListView android:id="#+id/lv_pizza" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"></ListView>
<Button android:layout_width="fill_parent" android:id="#+id/bt_add"
android:layout_height="wrap_content" android:text="hinzufügen"></Button>
<RelativeLayout android:layout_width="fill_parent" android:id="#+id/relativeLayout2" android:layout_height="fill_parent">
</RelativeLayout>
</LinearLayout>
Please help
This works for a linear layout, note the layout_weight 1 on the list -- that's what pushes the button to the bottom:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView android:id="#+id/lv_pizza"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button android:id="#+id/bt_add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hinzufügen" />
</LinearLayout>
This then looks like this in the UI editor:
Hi you can set like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
<ListView android:id="#+id/lv_pizza" android:layout_width="fill_parent"
android:layout_above="#+id/bt_add" android:layout_height="fill_parent" ></ListView>
<Button android:layout_width="fill_parent" android:id="#+id/bt_add"
android:layout_gravity="bottom" android:layout_height="wrap_content" android:text="hinzufügen"></Button>
</RelativeLayout>
Removing the RelativeLayout will push the button to bottom of the screen...
Use a layout_weight for the components inside the LinearLayout. If the ListView has a weight of 1.0, it should push the button to the bottom. I've done this with a ScrollLayout and it works well, allowing the component inside the scroll layout to actually scroll. You could put your ListView into a ScrollLayout to let it grow beyond the visible size.
Also, the second relativelayout also isn't necessary as it doesn't add anything.
You can set a marginTop in the Button until the bottom or change the layout to relative and set the position.