更改gridview的位置0处的项目布局

时间:2014-04-14 14:02:16

标签: android android-layout android-gridview

我有一个gridview,我正在用relativelayout充气。将此视为布局的示例:

0  1  2
3  4  5
......
......

我在布局中有progress bar,我只想应用于位置0的布局。并在设置适配器后使用async task更新它。当使用gridview我不能只访问位置0的视图,并且只要再次渲染就显示/隐藏progressbar。我应该怎么做才能修复gridview的第一个子节点的布局,并且在用户滚动项目时不要让它改变?

这是getView()的方法:

public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {

            convertView = inflater.inflate(R.layout.gridview_tvguide, null);
            holder = new ViewHolder();
            holder.image = (ImageButton) convertView.findViewById(R.id.image);
            holder.showTitle = (TextView) convertView
                    .findViewById(R.id.ShowTitle);
            holder.showDuration = (TextView) convertView
                    .findViewById(R.id.ShowTime);
                    //by default visibility is set to GONE
            holder.progBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }

            //logic to control the progressbar from asynctask
        if (this.updateNowPlaying){
            holder.progBar.setProgress(this.progress);
            return convertView;
        }

        ImageLoader.getInstance().displayImage(
                this.shows.get(position).getShowThumb(), holder.image);
        holder.showTitle.setText(this.shows.get(position).getShowTitle());
        holder.showDuration.setText(this.shows.get(position).getShowTime());

        return convertView;
    }

修改

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rlImage"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:paddingBottom="7dp"
    android:paddingRight="7dp" >

    <ImageButton
        android:id="@+id/image"
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:scaleType="centerCrop"
        android:src="@drawable/noimage" />

    <ImageButton
        android:id="@+id/imageHover"
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:scaleType="fitXY"
        android:src="@drawable/tile_selector_style" />

    <TextView
        android:id="@+id/ShowTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:hint="Show Title"
        android:paddingBottom="40dp"
        android:paddingRight="20dp"
        android:singleLine="true" />

    <TextView
        android:id="@+id/ShowTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:hint="Show Time"
        android:paddingBottom="20dp"
        android:paddingRight="20dp"
        android:singleLine="true" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:visibility="gone"
        android:layout_margin="0dp" />

</RelativeLayout>

这是我的gridview

<GridView
            android:id="@+id/gridView"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:clipToPadding="true"
            android:columnWidth="200dp"
            android:fitsSystemWindows="true"
            android:layout_weight="1"
            android:numColumns="auto_fit"
            android:stretchMode="columnWidth" >
        </GridView>

1 个答案:

答案 0 :(得分:1)

仅显示item 0 if/else初始化持有人后添加此代码的进度条:

if (position == 0) {
    holder.progBar.setVisibility(View.VISIBLE);
} else {
    holder.progBar.setVisibility(View.GONE);
}