0
Android Studio 0.8.10当使用ListFragment显示项目列表时,布局不显示正确
我正在使用ListFragment来显示图像和文本。但是,由于某些原因,每条记录之间有很大的空间。 一个记录将包含图像,标题。下一个应该从那里继续。但是,每个人之间都有很大的空间,我必须向下滚动才能进入下一个人。 LinearLayout高度由内容包装。
照片和标题应该相互跟随,应该没有空间。
这是我的布局将显示在ListFragment:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlist"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<ImageView
android:id="@+id/ivImage"
android:layout_width="match_parent"
android:layout_height="180dp"
android:contentDescription="Picture of newsfeed"
android:layout_marginTop="4dp"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ivImage"
android:textSize="30sp"
android:textColor="#ffffff"/>
</RelativeLayout>
</LinearLayout>
我getView功能,但我没有看到这里有问题,所有的数据都OK检索:
private class NewsFeedAdapter extends ArrayAdapter<NewsFeed> {
public NewsFeedAdapter(ArrayList<NewsFeed> newsFeedArrayList) {
super(getActivity(), 0, newsFeedArrayList);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.fragment_listfott, null);
}
NewsFeed newsFeed = getItem(position);
mIvImage = (ImageView)convertView.findViewById(R.id.ivImage);
mTvTitle = (TextView)convertView.findViewById(R.id.tvTitle);
Drawable drawable = new BitmapDrawable(getResources(), newsFeed.getImage());
mIvImage.setImageDrawable(drawable);
mTvTitle.setText(newsFeed.getTitle());
return convertView;
}
}
这是我滚动到下一个记录的图片:
下一个有很大的空间,必须向下滚动才能看到它。
您是否在包含imageView和TextView的RelativeLayout上尝试过“android:layout_alignParentTop = true”? – 2014-09-13 15:39:30
@FarhadFaghihi RelativeLayout不包含该属性(android:layout_alignParentTop =“true”)。但是,我确实将它添加到了LinearLayout中,但它不起作用。任何其他想法?谢谢。 – ant2009 2014-09-13 16:26:44
愚蠢的检查,但文本修剪?也许它在最后包含了一些crs。你的布局看起来不错,但是相关布局是完全多余的,我会把imageview和textview放到linearlayout中,或者更好,只使用textview并将图像指定为顶层复合可绘制(textviews可以包含顶部的图像,底部,左侧和右侧)。这样你的清单将会更有效率。 – rupps 2014-09-13 23:54:25