3

我正在使用 GridView。一切都很好。但是当滚动某些项目内的内容时,会转移到基线。但是当被触摸时,它又回到了顶部。这是一个疯狂的错误。

活动 Xml

enter code here
    <merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".HomeActivity" >

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <include layout="@layout/color_bar" />

        <RelativeLayout
            style="@style/default_bg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/rl_color_bar" >

            <RelativeLayout
                android:id="@+id/rl_top_icons"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true" >

                <Button
                    android:id="@+id/btn_ctp_logo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:background="@drawable/btn_ctp_selector" />

                <Button
                    android:id="@+id/btn_twitter"
                    android:layout_width="32dp"
                    android:layout_height="32dp"
                    android:layout_alignParentTop="true"
                    android:layout_toLeftOf="@+id/btn_facebook"
                    android:background="@drawable/btn_twitter_selector" />

                <Button
                    android:id="@+id/btn_facebook"
                    android:layout_width="32dp"
                    android:layout_height="32dp"
                    android:layout_alignParentTop="true"
                    android:layout_toLeftOf="@+id/btn_youtube"
                    android:background="@drawable/btn_facebook_selector" />

                <Button
                    android:id="@+id/btn_youtube"
                    android:layout_width="32dp"
                    android:layout_height="32dp"
                    android:layout_alignParentTop="true"
                    android:layout_toLeftOf="@+id/btn_linked_in"
                    android:background="@drawable/btn_youtube_selector" />

                <Button
                    android:id="@+id/btn_linked_in"
                    android:layout_width="32dp"
                    android:layout_height="32dp"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:background="@drawable/btn_twitter_selector" />
            </RelativeLayout>

                <RelativeLayout 
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/rl_top_icons">

                    <GridView 
                        android:id="@+id/grid_properties"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:numColumns="auto_fit"
                        android:verticalSpacing="6dp"
                        android:horizontalSpacing="6dp"
                        android:stretchMode="columnWidth"
                        android:gravity="center"
                        ></GridView>
                </RelativeLayout>
        </RelativeLayout>
    </RelativeLayout>

    <include layout="@layout/progress_screen" />

</merge>

适配器类

public class PropertyListAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<Property> data = null;
    private int layoutID;
    private LayoutInflater layout_inflater;
    ImageManagerGallery imageManager;
    DebugHelper debug = new DebugHelper(true);

    public PropertyListAdapter(Context c, int layoutID, ArrayList<Property> list){
        mContext = c;
        data = list;
        this.layoutID = layoutID;
        imageManager = new ImageManagerGallery(c);
    }

    public void add(ArrayList<Property> list){
        if(this.data != null){
            this.data.clear();
            this.data.addAll(list);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        if(this.data != null){
            return this.data.size();
        }
        return 0;
    }

    @Override
    public Property getItem(int position) {
        if(this.data != null){
            return this.data.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        if(this.data != null){
            return Common.getStringAsInteger(this.data.get(position).getSiteid());
        }
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VHHomeProperty viewHolder;
        Bitmap bitmap;

        if(convertView == null){
            this.layout_inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = this.layout_inflater.inflate(layoutID, null);

            viewHolder = new VHHomeProperty();
            viewHolder.iv_imageView = (ImageView)convertView.findViewById(R.id.iv_property_image);
            viewHolder.tv_text = (TextView)convertView.findViewById(R.id.tv_home_property_text);
            viewHolder.tv_title = (TextView)convertView.findViewById(R.id.tv_property_title);
            viewHolder.progress = (ProgressBar)convertView.findViewById(R.id.idProgressBar);

            convertView.setTag(viewHolder);
        }else{
            viewHolder = (VHHomeProperty) convertView.getTag();
        }



        if(this.data != null){
            Property locProp = this.data.get(position);
            viewHolder.tv_title.setText(locProp.getTitle());
            debug.print(locProp.getHomePageText());
            String htmlString = Html.fromHtml(Html.fromHtml(locProp.getHomePageText()).toString()).toString();
            debug.print(htmlString);            
            viewHolder.tv_text.setText(htmlString);

            try{
                viewHolder.iv_imageView.setTag(locProp.getImagePath());
                imageManager.displayImage(locProp.getImagePath(), viewHolder.iv_imageView, viewHolder.progress);

            }catch(Exception e){

            }
        }

        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)convertView.getLayoutParams();
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

        return convertView;
    }

}

grid_home_property.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/home_property_selector"
    android:gravity="top"
    android:padding="3dp" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/iv_property_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:src="@drawable/sample_property_image" />

        <ProgressBar
            android:id="@+id/idProgressBar"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" />
    </RelativeLayout>

    <TextView
        android:id="@+id/tv_home_property_text"
        style="@style/homePropertyText"
        android:layout_below="@+id/tv_property_title" />

    <TextView
        android:id="@+id/tv_property_title"
        style="@style/homePropertyTitle"
        android:layout_alignLeft="@+id/relativeLayout1"
        android:layout_below="@+id/relativeLayout1"
        android:layout_marginTop="14dp"
        android:text="Huntingdon" />

</RelativeLayout>
4

0 回答 0