2012-02-28 74 views
0

我正在嘗試使用listview中的可重複背景製作應用程序,但是我在可重複圖像之間的空格時遇到了一些麻煩。爲什麼是這樣?我該如何解決這個問題?ListView可重複背景創建空白

是否有另一種方法來創建可重複的背景?

public View getView(int position, View convertView, ViewGroup parent) { 
     LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View row = inflater.inflate(R.layout.event_list, parent, false); 
     List<Events> r = getEvent(); 
     Events e = r.get(position); 

     LoaderImageView image = (LoaderImageView) row.findViewById(R.id.imageView1); 
     TextView tittel = (TextView) row.findViewById(R.id.textView1); 
     TextView ingress = (TextView) row.findViewById(R.id.textView2); 

     tittel.setText(e.getEventName().toString()); 
     ingress.setText(e.getIngress().toString()); 
     image.setImageDrawable(e.getThumbnail().toString()); 



     Resources res = getResources(); 
     BitmapDrawable background = (BitmapDrawable) res.getDrawable(R.drawable.almanakk_bg); 
     background.setTileModeY(TileMode.REPEAT); 

     row.setBackgroundDrawable(background); 




     return row; 
    } 

ListView with repeatable background Almanakk背景圖像: almanakk_bg main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    > 
</ListView> 

Event_list.xml

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

<TableLayout 
    android:id="@+id/tableLayout1" 
    android:layout_width="60dp" 
    android:layout_height="match_parent" 
    android:background="@android:color/transparent"> 
    <no.havis.utils.LoaderImageView 
     android:id="@+id/imageView1" 
     android:layout_width="60dp" 
     android:layout_height="60dp" android:layout_margin="3dp"/> 
</TableLayout> 

<TableLayout 
    android:id="@+id/tableLayout2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/transparent"> 

    <TableRow 
     android:id="@+id/tableRow5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent"> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#000000"/> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="#000000"/> 

    </TableRow> 
</TableLayout> 

styles.xml

<resources> 

<style name="app_theme" parent="android:Theme"> 
    <item name="android:windowBackground">@drawable/background</item> 
    <item name="android:listViewStyle">@style/TransparentListView</item> 
    <item name="android:expandableListViewStyle">@style/TransparentExpandableListView</item> 
</style> 

<style name="TransparentListView" parent="@android:style/Widget.ListView"> 
    <item name="android:cacheColorHint">@android:color/transparent</item> 
    <item name="android:textColor">@android:color/black</item> 
</style> 

<style name="TransparentExpandableListView" parent="@android:style/Widget.ExpandableListView"> 
    <item name="android:cacheColorHint">@android:color/transparent</item> 
</style> 

+0

請郵寄包含列表視圖和列表項的佈局你的XML(如果您自定義它太)。而你確定,你的繪製doen't有它transperancy? – Hiral 2012-02-28 09:08:44

回答

0

有透明度的繪製。使用此圖像,而不是: enter image description here

+0

是的,這是因爲Android SDK的Draw 9補丁工具。刪除了空白,並工作。謝謝 – 2012-02-28 09:21:18

+0

是的。但是製作9貼片不會增加圖像空間,也不會產生問題。問題是因爲您的原始圖像具有透明度。反正,如果它對您有幫助,請接受答案。 :) – Hiral 2012-02-28 09:32:42

0
create drawable bg.xml file 

<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/back" 
    android:tileMode="repeat" /> 

and in your activitypage .xml write like this 

    <ListView 
     android:id="@+id/mylist" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:backgorund="@drawable/bg" > 
    </ListView> 
+0

這將工作,但背景應與內容滾動,而不是靜態背景。謝謝你。 – 2012-02-28 09:27:27

+0

然後嘗試像這樣設置列表視圖背景android:background =「@ android:color/transparent」 然後在外部佈局中設置您的背景。 – 2012-02-28 09:45:03