Hi,
I am having problem with a GridView within a RelativeLayout, which is
again within a ScrollView. The problem is that the height of the
RelativeLayout is not following the height of the contents of the
GridView. When there are more than one rows, the GridView is clipped
and a scrollbar appears, which is undesirable. I have tried to
illustrate my problem using an screenshot from the Android hierarchy
viewer (http://tinypic.com/r/98rs4n/4). You can see how the red
RelativeLayout box has clipped the second row of the GridView. I am
pasting the XML layout of the page (page.xml) and the individual grid
item (griditem.xml). I have used the following code to inflate the
grid items in the gridAdapter code:
/***********Start of gridAdapter snippet**********************/
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;
}
/***********End of gridAdapter snippet**********************/
/***********Start page.xml**********************/
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="8dip" android:paddingBottom="8dip"
android:paddingLeft="5dip" android:paddingRight="5dip"
>
<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"
/>
</RelativeLayout>
</ScrollView>
/***********End page.xml**********************/
/***********Start griditem.xml**********************/
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/icon_image"
android:layout_width="128dip"
android:layout_height="96dip">
</ImageView>
<TextView
android:id="@+id/icon_text"
android:layout_width="128dip"
android:layout_height="wrap_content"
android:text="TextView"
android:gravity="center_horizontal"
android:textColorHighlight="#656565">
</TextView>
</LinearLayout>
/***********End griditem.xml**********************/
Can you tell me what I should do to have the height of the
RelativeLayout follow the full length of the gridView?
Thanks,
Kuntal
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en