1

我有一个从 url 加载的图像水平列表。所以我有一个 ImageLoader,然后是一个适配器,然后是我的 Activity。我的 xml 布局如下所示:

主布局.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

  <com.devsmart.android.ui.HorizontalListView
      android:id="@+id/hlist_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"
      android:overScrollMode="always" > 
  </com.devsmart.android.ui.HorizontalListView>

</LinearLayout>

然后我的list.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" 
android:layout_height="match_parent"
android:orientation="vertical"
android:translationY="200dp" > <!-- make this dynamic -->

    <FrameLayout 
        android:id="@+id/mainlayout" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" >

       <ImageView
        android:id="@+id/prof_pic"    
        android:clickable="true"
        android:adjustViewBounds="true"
        android:layout_width="360dp" 
        android:layout_height="360dp" />

    <ProgressBar
        android:id="@+id/img_progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
        </FrameLayout>      

    <TextView
        android:id="@+id/sname"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/sdesc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

使用这种布局,结果是图A。灰色虚线是imageView,我们实际上看不到它,只能看到那些图像(绿色框)。我想要实现的是图 B 中的那个。

在此处输入图像描述

所以,为了解决这个问题,我尝试在我的 imageView 中添加

                  <ImageView
                android:id="@+id/prof_pic"    
                android:clickable="true"
                android:adjustViewBounds="true"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:maxWidth="360dp"
                android:maxHeight="360dp"
                android:minHeight="240dp"
                android:minWidth="240dp"
                 />

但是发生的事情是,当我打开应用程序时,我的图像列表看起来像图 A。但是当沿着图像滚动时,它调整到有点像图 B。但是当我滚动回第一个图像时,只有仅显示图像的第一个,或者有时,我的图像列表从我的第二个图像开始。这真是太疯狂了。

有什么方法可以在不破坏我的图像列表的情况下实现图 B,或者在应用程序启动时,它已经显示为图 B?

编辑:

这是我的适配器的样子:

public View getView(int position, View convertView, ViewGroup parent){
    ViewHolder holder = null;

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);



    if(convertView == null){
        convertView = inflater.inflate(R.layout.list_layout, null);
        holder = new ViewHolder();
        holder.txtShopName = (TextView) convertView.findViewById(R.id.shop_name);
        holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);
        holder.imageView = (ImageView) convertView.findViewById(R.id.prof_pic);
        holder.progBar = (ProgressBar) convertView.findViewById(R.id.img_progress);


        convertView.setTag(holder);
    }else{
        holder = (ViewHolder) convertView.getTag();
    }



    imageLoader=new ImageLoader(context.getApplicationContext(), holder.progBar);

    SRowItem sItem = (SRowItem) getItem(position);

    holder.txtName.setText(sItem.getShopName());
    holder.txtDesc.setText(sItem.getShopDesc());
    imageLoader.DisplayImage(sItem.getImageUrl(), holder.imageView);

    return convertView;
}
4

1 回答 1

2

尝试这样的事情:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);

ImageView imageView = (ImageView) LayoutInflater.from(context).inflate(R.layout.image, null);
imageView.setLayoutParams(params);
于 2013-04-03T08:04:32.693 回答