ListView可重复背景创建空白

时间:2012-02-28 09:04:51

标签: android android-layout android-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>

2 个答案:

答案 0 :(得分:0)

您的drawable有透明度。请改用此图片: enter image description here

答案 1 :(得分: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>