This HorizontalScrollView layout or its LinearLayout parent is useless - android

I am new in android programming I have problem with horizontalscrollview. I have error "This HorizontalScrollView layout or its LinearLayout parent is useless" on
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="lv.myproject.formula.MainFormula"
tools:ignore="MergeRootFrame"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/bgtest">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>

First of all, this is not an error but a warning - the code will still work correctly.
Now, as you can see, you have:
<LinearLayout ...>
<HorizontalScrollView ...>
</HorizontalScrollView ...>
</LinearLayout>
There is only one child in the LinearLayout - and it's another ViewGroup - therefore you can get rid of the outer LinearLayout and simply keep the HorizontalScrollView:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="lv.myproject.formula.MainFormula"
tools:ignore="MergeRootFrame"
android:layout_marginTop="50dp" >
...
</HorizontalScrollView>
However if you are adding any Views to the LinearLayout in your code (i.e. as siblings to your HorizontalScrollView) then the correct thing is to ignore this warning.

Related

Using ScrollView with LinearLayout, Android

In my xml file , i have one linearLayout and a button. The linearLayout contains a lot of textViews and checkboxes. So i wanted these textViews and checkboxes to scroll but the button should remain at its place i.e it should not scroll with the textViews. For this purpose, i cover my linearLayout with scrollView 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"
android:background="#drawable/homeo11" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/nexttodetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp">
</LinearLayout>
</ScrollView>>
<Button android:id="#+id/Next4"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Next" />
</LinearLayout>
But doing this , hid my button. means the textviews and checkboxes are now scrolling properly but i can't see my next button. I try replacing the scrollView layout:height from fill_parent to wrap_content but this didn't work as well. Any help?
Use a RelativeLayout as your root View and then set your component with align_above, align_parent_top and align_parent_bottom like this:
<?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"
android:background="#drawable/homeo11" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="#+id/Next4" >
<LinearLayout
android:id="#+id/nexttodetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp">
(...)
</LinearLayout>
</ScrollView>>
<Button
android:id="#+id/Next4"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
android:text="Next" />
</RelativeLayout>

Relative Layout inside a ScrollView - Not scrolling

I have a relative layout as child of Scrollview. I already tried a bunch of answers in here but the scroll isn't working.
That's my xml file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:fillViewport="true"
android:background="#drawable/home_bg_branco" >
<RelativeLayout
android:id="#+id/relative_categoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/categoria_placeholder_slider_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-3dp"
android:contentDescription="#string/home_placeholder_slider"
android:src="#drawable/home_placeholder_slider"
android:visibility="visible" />
<ImageSwitcher
android:id="#+id/home_imageswitcher_slider_listview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignBottom="#id/categoria_placeholder_slider_listview"
android:layout_alignLeft="#id/categoria_placeholder_slider_listview"
android:layout_alignRight="#id/categoria_placeholder_slider_listview"
android:layout_alignTop="#id/categoria_placeholder_slider_listview"
android:scaleType="fitXY" />
<ListView
android:id="#+id/listViewCategoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/home_imageswitcher_slider_listview"
tools:ignore="NestedScrolling" >
</ListView>
<ImageView
android:id="#+id/categoria_cores_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/categoria_placeholder_slider_listview"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:contentDescription="#string/img_cores"
android:src="#drawable/img_cores" />
<ImageView
android:id="#+id/categoria_destaque_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignStart="#id/categoria_placeholder_slider_listview"
android:contentDescription="#string/img_destaques"
android:src="#drawable/img_destaques" />
</RelativeLayout>
</ScrollView>
Another thing: i disabled the listview scroll to avoid conflicts.
Thanks in advance!
You should change layout_height of the RelativeLayout to match_parent:
<RelativeLayout
android:id="#+id/relative_categoria"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
Also remove android:fillViewport="true" from ScrollView.
In my project I have several ScrollViews exactly like this, and they work fine:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
UPDATE
One last thing I can propose is to remove ListView from the ScrollView as it can interfere with layout and scrolling.
Add this line to your onCreate()
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

Android LinearLayout with Button and FrameLayout using the Maximum Height

I am trying to make a layout where there are a LinearLayout and inside it I want a FrameLayout and a button.
I want the button to use the bottom of the linearlayout and to use the maximum width and the enough height for the button, using wrap content.
The other component, the FrameLayout I want to use it the remaining part of the screen.
How can I do it?
Here it the layout so far..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="snapIt"
android:text="#string/Capture" />
</LinearLayout>
Is not showing the button :s
Thanks alot in advance ;)
Better to work out with relative layout with button aligned to parent bottom and your frame layout above it occupying the rest space of the screen.Like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_capture"/>
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
use the following xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"
android:text="capture" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_capture"
/>
</RelativeLayout>
i am just trying to make these layout, after compare my layout code and your layout code, i find a different code, there is in my code. Did you missing it or just move it away cause it useless from the layout code ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<FrameLayout
android:id="#id/flayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world">
</FrameLayout>
</LinearLayout>

ScrollView layout or its RelativeLayout parent is possibly useless

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

Android ScrollView content disappearing on removing background attribute

I have a ScrollView in a LinearLayout along with a header LinearLayout on top. I have given the main LinearLayout a background. If I keep the background for the ScrollView everything displays fine. But If I add a lot of content then the ScrollView background stretches. So I want to keep the ScrollView transparent.
But if I remove the background attribute or if I try android:background="#android:color/transparent" the content inside the ScrollView vanishes. All I can see is the header and the background from the outer LinearLayouts.
This is how I want my Views:
<Linear Layout with background image>
<Header Linear Layout>
</Header Linear Layout>
<ScrollView with no background>
<Layouts in Scroll View>
</ScrollView>
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg"
android:orientation="vertical" >
<include layout="#layout/topbar" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
style="#style/Labels"
android:text="#string/posts_add_postcontent" />
<EditText
android:id="#+id/postsAddContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/posts_add_postcontent_h"
android:inputType="textMultiLine"
android:maxLength="3000"
android:minLines="3" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Note: The header LinearLayout is included via another file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/topbar"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="#layout/bgtop_repeat"
android:orientation="horizontal"
android:paddingTop="2dip" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:src="#drawable/cornerlogo" />
<Button
android:id="#+id/menubuton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/menubutton" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#layout/headshadow_repeat"
android:orientation="horizontal" />
</LinearLayout>
Thanks in advance :)
Try
android:layout_height="wrap_content"
in included layout

Categories

Resources