我有GridView
个自定义适配器,可以显示来自RSS频道的最新BBC新闻。我想在GridView
之上加载GIF图像或webview,直到我的RSS阅读完成(需要5秒钟)。这是我的代码:
private void readRssData() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
try{
@SuppressWarnings("resource")
RSSReader reader = new RSSReader();
String uri = "http://feeds.bbci.co.uk/news/world/rss.xml";
RSSFeed feed = reader.load(uri);
List<RSSItem> list = feed.getItems();
int c = 0;
for (RSSItem i: list) {
if (c > 15){
break;
}else{
addNewsItemInGrid(i.getTitle(), i.getDescription());
c++;
}
}
}catch (Exception ex){
Toast.makeText(getApplicationContext(), ex.toString(), Toast.LENGTH_SHORT).show();
}finally{
GridView gv = (GridView)findViewById(R.id.gridview);
gv.setAdapter(new RSSAdapter(getApplicationContext(), results));
}
}
}, 3000);
}
private ArrayList<SetAdd> results = new ArrayList<SetAdd>();
private void addNewsItemInGrid(String title, String description) {
SetAdd setadd = new SetAdd();
setadd.setTitle(title);
setadd.setDescription(description);
results.add(setadd);
}
<LinearLayout android:id="@+id/gridview_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/txt_DOTSTEXT"
>
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center" >
</GridView>
</LinearLayout>
你怎么看?如何使用图片或网页视图在GridView
之上加载图片
答案 0 :(得分:1)
将您的父版面更改为Framelayout
<FrameLayout android:id="@+id/gridview_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/txt_DOTSTEXT"
>
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center" >
</GridView>
// add a loading image view here with some id .. and adjust its visibility inside the activity run time
</FrameLayout>
答案 1 :(得分:1)
将您的xml文件更改为 -
<LinearLayout android:id="@+id/gridview_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/txt_DOTSTEXT"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/myimage"
android:id="@+id/imageview1"/>
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center" >
</GridView>
</LinearLayout>
并在源代码中添加以下代码,以便在读取rss后删除图像
ImageView imageView = (ImageView) findViewById(R.id.imageview1);
imageView.setVisibility(View.GONE);