Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To add Grid view inside a scroll view by using a custom Gridview <strong>ExpandableHeightGridView</strong></p> <p>please follow the example as below</p> <p><strong>ExpandableHeightGridView.java</strong></p> <pre><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) { // 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 &gt;&gt; 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; } } </code></pre> <p><strong>Xml file</strong></p> <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/scroll" android:background="@android:color/white" &gt; &lt;RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" &gt; &lt;RelativeLayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="50dp" android:background="@android:color/white" &gt; &lt;TextView android:id="@+id/txbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="9dp" android:text="Textview" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#2c627e" android:textStyle="bold" /&gt; &lt;/RelativeLayout&gt; &lt;yourpackagename of ExpandableHeight.class.ExpandableHeightGridView android:id="@+id/gridlist" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:horizontalSpacing="10dp" android:layout_below="@+id/header" android:numColumns="2" android:scrollbarStyle="outsideOverlay" android:scrollbars="vertical" android:verticalScrollbarPosition="right" android:verticalSpacing="10dp" /&gt; &lt;RelativeLayout android:layout_width="match_parent" android:layout_height="120dp" android:background="#034E6D" android:layout_marginTop="5dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:id="@+id/view_rl" android:layout_below="@+id/gridlist" &gt; &lt;!-- &lt;TextView android:id="@+id/newsdata_grid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/newsdatas" android:text="juijb" android:maxLines="3" android:layout_marginLeft="10dp" android:textSize="20dp" /&gt; --&gt; &lt;ImageView android:id="@+id/datas_images" android:layout_width="60dp" android:layout_height="50dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_marginTop="5dp" android:adjustViewBounds="true" android:src="@drawable/bike_icon" /&gt; &lt;TextView android:id="@+id/data_grids" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/datas_images" android:layout_centerHorizontal="true" android:layout_marginTop="10dp" android:gravity="center" android:text="VIEWS" android:textColor="@android:color/white" android:textSize="10dp" /&gt; &lt;/RelativeLayout&gt; &lt;View android:layout_width="fill_parent" android:layout_height="10dp" android:background="@android:color/white" android:layout_below="@+id/view_rl"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p></p> <p>And in the Activity class</p> <pre><code> ExpandableHeightGridView gridview=(ExpandableHeightGridView)findViewById(R.id.gridlist); gridview.setExpanded(true); </code></pre> <p>This will show a gridview inside a scrollview,Hope this will help you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload