I am having a problem with a GridView in RelativeLayout, which is again in ScrollView. The problem is that the height of the RelativeLayout does not match the height of the contents of the GridView. When there are multiple rows, the GridView is cropped and a scroll bar appears, which is undesirable. I tried to illustrate my problem using a screenshot from the Android hierarchy viewer. You can see how the red RelativeLayout field cropped the second row of the GridView. I am inserting an XML page layout (page.xml) and a separate grid element (griditem.xml). I used the following code to inflate mesh elements in gridAdapter code:
/ *********** The beginning of the gridAdapter fragment *********************** /
public View getView(int position, View convertView, ViewGroup parent) { View v; if(convertView==null){ li = LayoutInflater.from(mContext); v = li.inflate(R.layout.griditem, null); //code for fetching textView and imageUrl content TextView tv = (TextView)v.findViewById(R.id.icon_text); tv.setText(textContent); ImageView iv = (ImageView)v.findViewById(R.id.icon_image); //code for fetching and attaching image to imageView } else { v = convertView; } return v; }
/ *********** The end of the gridAdapter fragment *********************** /
/ *********** Start page .xml *********************** /
<TextView android:id="@+id/title" android:layout_weight="1" android:layout_width="320dip" android:layout_height="wrap_content" android:singleLine="false" android:textStyle="bold" android:textSize="14dip" /> <ImageView android:id="@+id/image" android:layout_below="@+id/title" android:adjustViewBounds="true" android:layout_width="128dip" android:layout_height="96dip" android:layout_marginRight="4dip" /> <TextView android:id="@+id/name" android:layout_weight="1" android:layout_below="@+id/title" android:layout_toRightOf="@+id/image" android:layout_width="192dip" android:layout_height="wrap_content" android:paddingTop="2dip" android:textSize="12dip" android:paddingLeft="2dip" /> <TextView android:id="@+id/location" android:layout_weight="1" android:layout_below="@+id/name" android:layout_toRightOf="@+id/image" android:layout_width="192dip" android:layout_height="wrap_content" android:paddingTop="2dip" android:textSize="12dip" android:paddingLeft="2dip" /> <TextView android:id="@+id/date1" android:layout_weight="1" android:layout_below="@+id/location" android:layout_toRightOf="@+id/image" android:layout_width="192dip" android:layout_height="wrap_content" android:paddingTop="2dip" android:textSize="10dip" android:paddingLeft="2dip" /> <TextView android:id="@+id/date2" android:layout_weight="1" android:layout_below="@+id/date1" android:layout_toRightOf="@+id/image" android:layout_width="192dip" android:layout_height="wrap_content" android:paddingTop="2dip" android:textSize="10dip" android:paddingLeft="2dip" /> <Button android:id="@+id/button1" android:text="buttonText1" android:layout_weight="1" android:layout_below="@+id/image" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="96dip" /> <Button android:id="@+id/button2" android:text="buttonText2" android:layout_weight="1" android:layout_below="@+id/image" android:layout_toRightOf="@+id/button1" android:layout_height="wrap_content" android:layout_width="wrap_content" /> <Button android:id="@+id/button3" android:text="Text" android:layout_weight="1" android:layout_below="@+id/image" android:layout_toRightOf="@+id/button2" android:layout_height="wrap_content" android:layout_width="wrap_content" /> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/button1" android:layout_weight="1" android:numColumns="auto_fit" android:verticalSpacing="10dip" android:horizontalSpacing="10dip" android:stretchMode="columnWidth" android:gravity="center" />
/ *********** End page.xml *********************** /
/ *********** Run griditem.xml ********************** /
Android: Gravity = "center_horizontal">
/ *********** End griditem.xml *********************** /
Can you tell me what I have to do so that the height of the RelativeLayout matches the entire length of the gridView?
Thank Kuntal [Alt text] [1]
Here is a screenshot: http://tinypic.com/r/98rs4n/4
android
Kuntal
source share