2014-09-13 104 views
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; 
     } 
    } 

這是我滾動到下一個記錄的圖片: enter image description here

下一個有很大的空間,必須向下滾動才能看到它。 enter image description here

+0

您是否在包含imageView和TextView的RelativeLayout上嘗試過「android:layout_alignParentTop = true」? – 2014-09-13 15:39:30

+0

@FarhadFaghihi RelativeLayout不包含該屬性(android:layout_alignParentTop =「true」)。但是,我確實將它添加到了LinearLayout中,但它不起作用。任何其他想法?謝謝。 – ant2009 2014-09-13 16:26:44

+0

愚蠢的檢查,但文本修剪?也許它在最後包含了一些crs。你的佈局看起來不錯,但是相關佈局是完全多餘的,我會把imageview和textview放到linearlayout中,或者更好,只使用textview並將圖像指定爲頂層複合可繪製(textviews可以包含頂部的圖像,底部,左側和右側)。這樣你的清單將會更有效率。 – rupps 2014-09-13 23:54:25

回答

0

我按比例縮小了背景圖片的實際尺寸,因爲它太大了。