ScrollView applied only to LinearLayout child instead of the LinearLayout itself - android

I´m trying to make a scrollview but it is getting itself applied on the 2 lists I have in the LinearLayout, scrollview child. I want to be able to scroll, vertically, through the entire layout, but it only lets me scroll on the lists. What did I do wrong and could it be fixed?
Thanks in advance
content_habilitacoes.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.luis.trabindividual.HabilitacoesActivity"
tools:showIn="#layout/app_bar_habilitacoes">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/content_habilitacoes_titulo_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/content_habilitacoes_titulo_1"
style="#style/contentMainTitle"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ListaHab1"/>
<TextView
android:id="#+id/content_habilitacoes_titulo_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/content_habilitacoes_titulo_2"
style="#style/contentMainTitle"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ListaHab2"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
How it is being displayed:

Related

Android HorizontalScrollView nesting HorizontalScrollView

I want to have a HorizontalScrollView containing a HorizontalScrollView.
This is my current Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.erik.playground.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:clipChildren="false"
android:nestedScrollingEnabled="true"
android:layout_marginTop="40dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_height="20dp"
app:cardElevation="9dp"
android:layout_width="500dp"/>
<HorizontalScrollView
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:layout_height="20dp"
app:cardElevation="9dp"
android:layout_width="600dp"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
Right now the inner HorizontalScrollView does not scroll and only the outer one scrolls.
Is there a possibility to make that work?

AdView attached to bottom doesn't let me see last item in Recyclerview

I have a RelativeLayout in wich I have a RecyclerView and a LinearLayout with an AdView inside. The RecyclerView has many items and when I was unable to show them in the screen I just had to scroll down to see them, but now that I added the LinearLayout attached to the bottom of the screen with the AdView inside I scroll down and I'm not able to see the last item of the RecyclerView. I'm attaching the LinearLayout to the bottom but it seems that It's above the RecyclerView and I want the RecyclerView to show items in the screen but not behind the LinearLayout. Is it possible?
Here's my XML for the Layout:
<?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"
xmlns:ads="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="#+id/rvGeneric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
<com.google.android.gms.ads.AdView
android:id="#+id/adViewBaseRefresh"
android:layout_width="fill_parent"
android:layout_height="53dp"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"
android:layout_marginBottom="3dp">
</com.google.android.gms.ads.AdView>
</LinearLayout>
A relative layout needs "Relative" relationships defined within the XML. As you don't have any (other than align the linear layout on the bottom), the result is the LL and RecyclerView are overlapping.
Add the line android:layout_below="#id/rvGeneric" to the linear layout
<?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"
xmlns:ads="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ll_ad"
android:layout_alignParentBottom="true"
android:gravity="center">
<com.google.android.gms.ads.AdView
android:id="#+id/adViewBaseRefresh"
android:layout_width="fill_parent"
android:layout_height="53dp"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"
android:layout_marginBottom="3dp">
</com.google.android.gms.ads.AdView>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rvGeneric"
android:layout_above="#id/ll_ad"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</RelativeLayout>
For this I'd personally use a LinearLayout like below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.example.geoff.stackoverflowtesting.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/rvGeneric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TESTING2"
android:background="#FFF000"
android:textSize="200dp"
android:scrollbars="vertical">
</TextView>
</LinearLayout>
</ScrollView>
<TextView
android:id="#+id/adViewBaseRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TESTING"
android:textSize="30dp"
android:textColor="#FFF000"
android:background="#000000"
android:layout_marginBottom="3dp"
android:layout_weight="0.1">
</TextView>
</LinearLayout>
If you particularly want to use a RelativeLayout then:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.gfaiers.layoutexamples.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rvGeneric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
<com.google.android.gms.ads.AdView
android:id="#+id/adViewBaseRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"
android:layout_marginBottom="3dp">
</com.google.android.gms.ads.AdView>
</RelativeLayout>

Android: Can't make ListView full size

I am trying to make ListView full-screen size, but every time in my scroll view I can see just one item from ListView.
There is my 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="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<!-- progress -->
<ProgressBar android:id="#+id/login_progress" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:visibility="gone" />
<ScrollView android:id="#+id/main_form" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="#+id/countriesList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
That's how it looks:
How do I want to make it look:
I can't achieve this without harcode height of ListView.
To put ListView inside ScrollView very bad idea. Try to not do it
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#+id/countriesList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
it because in your top LinearLayout use padding. so, you can delete the all padding
so, it should be like this :
<?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="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- progress -->
<ProgressBar android:id="#+id/login_progress" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:visibility="gone" />
<ScrollView android:id="#+id/main_form" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="#+id/countriesList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
</ScrollView>

How to add multiple charts inside one fragment with scroll view using mpandroidchart?

As the title says I want to add multiple bar charts inside one tab fragment with a scroll view. I have added four charts inside one fragment but unable to scroll them. In future there will be more than four and anyhow I have to make the fragment scroll so that user can see multiple bar charts easily.
I have tried to make it scroll by adding android:fillViewport="true" but it is not working.
I have been searching about this for hours and didn't get anything according to my requirement.
Any help would be appreciated.
Thank you.
Daily_layout (fragment layout which contains multiple charts)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:fillViewport="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="150dp" />
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart1"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="160dp" />
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart2"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="320dp" />
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart3"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="480dp" />
</RelativeLayout>
Add android:isScrollContainer="false" in ScrollView and make it parent
Change height to wrap_content for the layouts which are inside the ScrollView
The layout:
<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:fillViewport="true"
android:isScrollContainer="false"
tools:context=".ReportFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.highsoft.highcharts.Core.HIChartView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/bar_chart1"/>
<com.highsoft.highcharts.Core.HIChartView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/bar_chart1"/>
<com.highsoft.highcharts.Core.HIChartView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/bar_chart1"/>
<com.highsoft.highcharts.Core.HIChartView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/bar_chart1"/>
<com.highsoft.highcharts.Core.HIChartView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/bar_chart1"/>
</LinearLayout>
</ScrollView>

how do I align a view on top of 1 of 2 views

Click on image, replace with relativelayout as shown below. This bottom section should be below the listview. Problem is I dont see the listview in the design preview of my IDE.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:id="#+id/bottomSection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:onClick="switch"
android:src="#drawable/ic_edit"
android:visibility="visible" />
<RelativeLayout
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</RelativeLayout>
</LinearLayout>
<ListView
android:id="#+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottomSection" />
</RelativeLayout>
You can put the two linearlayouts in another linearlayout, And use parent linearlayout for reference in Listview.
Like this:
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.tempproj.MainActivity" >
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/lay1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible" >
</LinearLayout>
<LinearLayout
android:id="#+id/lay2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" >
</LinearLayout>
</LinearLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/container" />
</RelativeLayout>
So your Listview will be on top of container LinearLayout, regardless of which linearlayout is visible inside that. Hope it helps.
Try this way,hope this will help you to solve your problem.
In you xml vertical LinearLayout as parent layout and A,B and ListView as child,given weight to ListView so it can adjust height even if no A or B visible and in case of shown A or B you have to implement on click of both in activity like when A show and click show B and hide A and vise versa.
<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:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible">
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>

Categories

Resources