I have the following GridView:
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="120dp"
app:layout_constraintTop_toTopOf="parent"
android:numColumns="2"
android:gravity="center" />
and the following Item:
<?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:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
>
<TextView
android:id="#+id/planlayout_teams_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
tools:text="Tambora 0 - 0 Balagath"
android:textStyle="bold"
android:paddingTop="4dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:gravity="center"/>
<TextView
android:id="#+id/planlayout_status_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
tools:text="noch unentschieden"
android:gravity="center"/>
</LinearLayout>
<TextView
android:id="#+id/planlayout_menu_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text=".\n.\n."
android:textSize="12sp" />
</LinearLayout>
And everything is working fine except for the last item(s). Whether there is one or two items left, the whole row is not displayed. I googled a lot but nothing could help me.
Edit: I have the same "problem" as here: Custom GridView's Last row items not showing fully but those links don't help me.
I think the problem is about your layout. Your adapter load your all items but your layout not let you see last item because of your top margin.
You can edit your grid layout like this. Can you try this way.
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="120dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:numColumns="2"
android:gravity="center" />
just try this -->
<GridView
android:id="#+id/mGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:columnWidth="172dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"/>
Or try with custom gridview
your gridview code on layout something like this :--
<com.yourpackagename.MyGridView
android:id="#+id/mGridView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2"
android:adjustViewBounds="true"
android:columnWidth="90dp"
android:verticalSpacing="-2dp"
android:horizontalSpacing="-10dp"
android:stretchMode="columnWidth"
android:scrollbars="vertical"
android:fastScrollEnabled="true"
/>
MyGridview activity:-
public class MyGridView extends GridView {
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightSpec;
if (getLayoutParams().height == LayoutParams.MATCH_PARENT) {
heightSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
}
else {
heightSpec = heightMeasureSpec;
}
super.onMeasure(widthMeasureSpec, heightSpec);
}
}
In your mainactivity (activity where you want to declare the gridview)
private MyGridView mGridView;
//also add your adapter of gridview
.
.
oncreate(){
mGridView = getView().findViewById(R.id.mGridView);
//then attach your adapter
adapter = new GridViewAdapter(getContext()...whatever parameters you have in your constructor);
mGridView.setAdapter(adapter);
try this custom gridview...still it doesnt worked let me know
Related
This question already has answers here:
RecyclerView inside ScrollView is not working
(26 answers)
Closed 6 years ago.
I have a recyclerView inside my LinearLayout.
<ScrollView 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"
android:id="#+id/book_detail_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.BookDetailActivity">
<LinearLayout
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:orientation="vertical">
<ImageView
android:layout_width="250dp"
android:layout_height="270dp"
android:id="#+id/book_image"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_gravity="center"
android:src="#drawable/book_default"/>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:background="#EEEEEE"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/book_authors"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:fontFamily="sans-serif-condensed" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:max="5"
android:id="#+id/book_rating"
android:stepSize="0.5"
android:paddingTop="10dp"
android:isIndicator="true"
android:progressTint="#FFA500"
android:secondaryProgressTint="#D1D6D8"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingLeft="5dp"
android:id="#+id/book_rating_text"
android:fontFamily="sans-serif-condensed" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/book_reviews_text"
android:textColor="#color/redColor"
android:fontFamily="sans-serif-condensed" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:background="#EEEEEE"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:fadingEdge="vertical"
android:fadingEdgeLength="20dp"
android:paddingTop="#dimen/activity_vertical_margin"
android:id="#+id/book_description"
android:onClick="toggleText"
android:ellipsize="end"
android:maxLines="3" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:id="#+id/book_description_below_line"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:background="#EEEEEE"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/dark_translucent_black"
android:textAlignment="center"
android:textSize="15dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:text="People near you who are willing to lend this book"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/lender_recycler_view"
android:layout_width="match_parent"
android:layout_height="400dp"
android:scrollbars="vertical" />
</LinearLayout>
</ScrollView>
The problem is that when I inflate this recyclerView, the complete activity is not scrolling (Only the part of recycler view does). Moreover I have specify height of recyclerView otherwise I am not able to see it.
So my two problems are:
How to give this RecyclerView hight dynamically (layout_height: wrap_content isn't working)
How to scroll the entire activity (and not just the recyclerView part) when content is more.
P.S I am new to Android, though I have implemented recyclerView earlier but in those cases there was only one element (one recyclerView inside a parent LinearLayout)
ExpandableHeightListView.java
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;
import android.content.Context;
public class ExpandableHeightListView extends ListView
{
boolean expanded = false;
public ExpandableHeightListView(Context context)
{
super(context);
}
public ExpandableHeightListView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public ExpandableHeightListView(Context context, AttributeSet attrs,
int defStyle)
{
super(context, attrs, defStyle);
}
public boolean isExpanded()
{
return expanded;
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (isExpanded())
{
// Calculate entire height by providing a very large height hint.
// But do not use the highest 2 bits of this integer; those are
// reserved for the MeasureSpec mode.
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
else
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded)
{
this.expanded = expanded;
}
}
Add this customized java file and use it in xml.
and in your MainActivity do like this:
ExpandableHeightListView listview= (ExpandableHeightListView) findViewById(R.id.comment_listview);
and set adapter and set one property
listview.setAdapter("Your Adapter");
listview.setExpanded(true);
sorry for my bad English ,I want to display 2 Grid views and one text view and image view in android ,Here below my XML code any one help me How to achieve that
I want to display 2 Grid views and one text view and image view in android
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="100sp"
android:src="#drawable/ic_launcher"
/>
<GridView
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/image"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
<TextView
android:id="#+id/text"
android:layout_below="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Treding"
/>
<GridView
android:id="#+id/gridview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/text"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
</RelativeLayout>
</ScrollView>
What you should do is the following:
Expandable height gridview:
This means the more you add items to the GridView, the more it will expand. (This is what you need).
Now how to do it is simple:
First you need to create a java class:
public class ExpandableHeightGridView extends GridView {
boolean expanded = false;
public ExpandableHeightGridView(Context context)
{
super(context);
}
public ExpandableHeightGridView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public ExpandableHeightGridView(Context context, AttributeSet attrs,
int defStyle)
{
super(context, attrs, defStyle);
}
public boolean isExpanded()
{
return expanded;
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
// This is a definite hack!!
if (isExpanded())
{
// Calculate entire height by providing a very large height hint.
// View.MEASURED_SIZE_MASK represents the largest height possible.
int expandSpec = View.MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
View.MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
else
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded)
{
this.expanded = expanded;
} }
Then in xml layout:
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="100sp"
android:src="#drawable/ic_launcher"
/>
<custom.ExpandableHeightGridView
android:id="#+id/grid1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="5dp"
android:horizontalSpacing="10dp"
android:isScrollContainer="false"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
<TextView
android:id="#+id/text"
android:layout_below="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Treding"
/>
<custom.ExpandableHeightGridView
android:id="#+id/grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="5dp"
android:horizontalSpacing="10dp"
android:isScrollContainer="false"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
</RelativeLayout>
</ScrollView>
Then in your activity:
grid = (ExpandableHeightGridView) findViewById(R.id.grid);
grid.setExpanded(true);
grid.setAdapter(your adapter);
**Let me know if you need further assistance **
I'm using ExpandableHeightGridView but I don't manage to calculate the correct height of the gridview, I use custom rows made by an external layout, but it cuts several rows at the bottom,
here's the code:
public class ExpandableHeightGridView extends GridView {
boolean expanded = false;
public ExpandableHeightGridView(Context context) {
super(context);
}
public ExpandableHeightGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExpandableHeightGridView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public boolean isExpanded() {
return expanded;
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (isExpanded()) {
int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
}
}
Custom Row
<?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:background="#null"
android:orientation="vertical" >
<TextView
android:id="#+id/textViewBioAnno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center_horizontal"
android:text="TextView"
android:textColor="#color/oro"
android:textSize="20sp" />
<TextView
android:id="#+id/textViewBioTesto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="TextView"
android:textSize="15sp" />
</LinearLayout>
My Layout
<?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:background="#color/sfondo"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_marginTop="10dp"
android:scaleType="fitCenter"/>
<ImageButton
android:id="#+id/imageView1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="12dp"
android:background="#null"
android:scaleType="fitXY" />
</RelativeLayout>
<TextView
android:id="#+id/textViewBio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/bio"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/oro" />
<******.ExpandableHeightGridView
android:id="#+id/mebersListGridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:horizontalSpacing="10dp"
android:isScrollContainer="false"
android:numColumns="1"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:src="#drawable/fondo_pagina" />
<ImageView
android:id="#+id/ImageView02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginRight="70dp"/>
<ImageView
android:id="#+id/ImageView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"" />
</LinearLayout>
</ScrollView>
</LinearLayout>
My activity:
...
g = (ExpandableHeightGridView) findViewById(R.id.mebersListGridView);
arrayAdapter = new StandardArrayAdapter(this,
R.layout.activity_bio, arrayList);
g.setExpanded(true);
g.setAdapter(arrayAdapter);
...
I am using a GridView in a Relative layout. I want the GridView to show
up as tall as needed to show all the rows. However, I am seeing only
one row when set (layout_width=MATCH_PARENT and)
layout_height=WRAP_CONTENT. If I set layout_height to a size that
equals mulitple rows, then I do see those rows.
<?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:gravity="center"
>
<RelativeLayout
android:id="#+id/layout_month"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/textv_month_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:gravity="center_horizontal|center_horizontal"
android:textColor="#ffffff"
android:textSize="7dp" />
<ImageView
android:id="#+id/top_bar"
android:layout_width="fill_parent"
android:layout_height="15dp"
android:layout_below="#+id/textv_month_name"
android:background="#drawable/calendar_top_small"
android:clickable="false" />
<GridView
android:id="#+id/gridv_inner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/top_bar"
android:layout_gravity="center"
android:clickable="false"
android:gravity="center"
android:numColumns="7"
android:stretchMode="columnWidth"
>
</GridView>
<Button
android:id="#+id/monthBtn"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent" />
</RelativeLayout>
</RelativeLayout>
Any Help will be appreciable
This is a very useful answer.
The GridView didn’t like the wrap_content of its height when it was put in a vertically tight space; it only showed a single row of items (scrolling all content in that single row).
The short version of my fix includes sub classing the GridView and overriding the onMeasure method. The essence of the fix focuses on setting the measured height spec to a ridiculously large number.
MyGridview.Java
package com.arun.calendar;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;
public class MyGridView extends GridView {
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightSpec;
if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
// The two leftmost bits in the height measure spec have
// a special meaning, hence we can't use them to describe height.
heightSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >>2, MeasureSpec.AT_MOST);
}
else {
// Any other height should be respected as is.
heightSpec = heightMeasureSpec;
}
super.onMeasure(widthMeasureSpec, heightSpec);
}
}
And the new XML file
<?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:gravity="center" >
<RelativeLayout
android:id="#+id/layout_month"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textv_month_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:gravity="center_horizontal|center_horizontal"
android:textColor="#ffffff"
android:textSize="7dp" />
<ImageView
android:id="#+id/top_bar"
android:layout_width="fill_parent"
android:layout_height="15dp"
android:layout_below="#+id/textv_month_name"
android:background="#drawable/calendar_top_small"
android:clickable="false" />
<com.arun.calendar.MyGridView
android:id="#+id/gridv_inner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/top_bar"
android:layout_gravity="center"
android:clickable="false"
android:gravity="center"
android:numColumns="7"
android:stretchMode="columnWidth" />
</RelativeLayout>
<Button
android:id="#+id/monthBtn"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent" />
</RelativeLayout>
And in java file
MyGridView viewHolder.gridView = (MyGridView) v.findViewById(R.id.gridv_inner);
in my code there is four listview how do i make screen scrollable to show all data of all listview? not this code make listview scrollable i dont want listview scrolling want ScreenScrollable like this image
<?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="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/imagelogo2"
android:orientation="horizontal" >
<ImageView
android:id="#+id/test_button_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingTop="20dp"
android:src="#drawable/back" >
</ImageView>
<ImageView
android:id="#+id/test_button_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingLeft="5dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:src="#drawable/options1" />
</RelativeLayout>
<TextView
android:id="#+id/ElemenrySchool"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/btnback"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:text="elementry"
android:textSize="17dp" >
</TextView>
<LinearLayout
android:id="#+id/lytContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/border2"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ListView
android:id="#+id/listMainMenu11"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dip"
android:fadeScrollbars="true"
android:listSelector="#drawable/listview_selector" />
</LinearLayout>
<TextView
android:id="#+id/MiddleSchool"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:text="Middle"
android:textSize="17dp" >
</TextView>
<LinearLayout
android:id="#+id/lytContent2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/border2"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ListView
android:id="#+id/listMainMenu22"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dip"
android:fadeScrollbars="true"
android:listSelector="#drawable/listview_selector" />
</LinearLayout>
<TextView
android:id="#+id/HighSchool"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/btnback"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:text="HighSchool"
android:textSize="17dp" >
</TextView>
<LinearLayout
android:id="#+id/lytContent3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/border2"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ListView
android:id="#+id/listMainMenu33"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dip"
android:fadeScrollbars="true"
android:listSelector="#drawable/listview_selector" />
</LinearLayout>
<TextView
android:id="#+id/AtipicalSchool"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/btnback"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:text="Atipical"
android:textSize="17dp" >
</TextView>
<LinearLayout
android:id="#+id/lytContent4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/border2"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ListView
android:id="#+id/listMainMenu44"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dip"
android:fadeScrollbars="true"
android:listSelector="#drawable/listview_selector" />
</LinearLayout>
</LinearLayout>
use this custom listview component inside scrollview.
package com.app.Settings;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;
public class ExpandableHeightListView extends ListView
{
boolean expanded = false;
public ExpandableHeightListView(Context context)
{
super(context);
}
public ExpandableHeightListView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public ExpandableHeightListView(Context context, AttributeSet attrs,int defStyle)
{
super(context, attrs, defStyle);
}
public boolean isExpanded()
{
return expanded;
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
// HACK! TAKE THAT ANDROID!
if (isExpanded())
{
// Calculate entire height by providing a very large height hint.
// But do not use the highest 2 bits of this integer; those are
// reserved for the MeasureSpec mode.
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
else
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded)
{
this.expanded = expanded;
}
}
HOW TO USE IN XML?
<yourPackageName.ExpandableHeightListView
android:id="#+id/expandableHeightlist1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:fadingEdge="none"
android:focusable="false"
android:scrollbars="none"
>
</yourPackageName.ExpandableHeightGridView>
and set
yourListView.setExpanded(true);
By using this custom component you can set multiple listview inside scrollview. i am using this custom component.
Enjoy :)
Never use two listview inside Scrollview
Don't try to use listview , use a LinearLayout instead , if you have got a fixed number of views. As listview will have its own scroll and this won't be a good user experience too.