小编Kun*_*tal的帖子

Android RelativeLayout高度不遵循GridView高度

我在RelativeLayout中有一个GridView的问题,它在ScrollView中也是如此.问题是RelativeLayout的高度不遵循GridView内容的高度.当有多行时,GridView会被剪裁并出现滚动条,这是不可取的.我试图使用Android层次结构查看器中的屏幕截图来说明我的问题.您可以看到红色RelativeLayout框如何剪切GridView的第二行.我粘贴页面的XML布局(page.xml)和单个网格项(griditem.xml).我使用以下代码来扩展gridAdapter代码中的网格项:

/***********gridAdapter片段的开始**********************/

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;
}
Run Code Online (Sandbox Code Playgroud)

/***********gridAdapter片段结尾**********************/

/***********启动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" …
Run Code Online (Sandbox Code Playgroud)

android

7
推荐指数
1
解决办法
3376
查看次数

标签 统计

android ×1