在滑行将图像加载到ImageView之前确定ScrollView高度?

时间:2017-05-19 19:28:54

标签: java android android-scrollview android-glide

我正在使用Glide将图像从Web加载到ImageView中,ImageView是布局的一部分,在ListView中定义一个项目。 该过程在列表的适配器" getView"内完成。功能

问题是滚动视图高度似乎是在滑行下载图像之前确定的,然后当下载图像时,无法向下滚动以查看整个图像,因为滚动视图高度包装内容之前的状态图像已加载。

适配器代码如下:

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    // Get the data item for this position
    NewsBlockInfo newsBlockInfo = getItem(position);
    // Check if an existing view is being reused, otherwise inflate the view
    final ViewHolder viewHolder; // view lookup cache stored in tag
    if (convertView == null) {
        // If there's no view to re-use, inflate a brand new view for row
        viewHolder = new ViewHolder();
        LayoutInflater inflater = LayoutInflater.from(getContext());
        convertView = inflater.inflate(R.layout.list_item, parent, false);
        viewHolder.txtTitle = (TextView) convertView.findViewById(R.id.txt_title);
        viewHolder.txtBody = (TextView) convertView.findViewById(R.id.txt_body);
        viewHolder.imageExtra = (ImageView) convertView.findViewById(R.id.img_extra);
        // Cache the viewHolder object inside the fresh view
        convertView.setTag(viewHolder);
    } else {
        // View is being recycled, retrieve the viewHolder object from tag
        viewHolder = (ViewHolder) convertView.getTag();
    }
    // Populate the data from the data object via the viewHolder object
    // into the template view.
    viewHolder.txtTitle.setText(newsBlockInfo.Title);
    viewHolder.txtBody.setText(newsBlockInfo.Body);
    Glide.with(getContext())
            .load(newsBlockInfo.ImageUrl)
            .into(viewHolder.imageExtra);

    // Return the completed view to render on screen
    return convertView;
}

项目布局xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/news_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical">

<TextView
    android:id="@+id/txt_title"
    ...

<TextView
    android:id="@+id/txt_body"
    ...

<ImageView
    android:id="@+id/img_extra"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:scaleType="fitCenter"
    android:background="#BBDEFB"/>

</LinearLayout>

片段布局xml:

 <ListView
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/news_list"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     tools:context="haggaidev.nationui.MainActivity$PlaceholderFragment">

 </ListView>

有没有办法去刷新&#34; scrollview重新包装内容?

0 个答案:

没有答案