0

我想在activity的两个listview之间画箭头,概念图如下图。

每条箭头线连接左侧列表视图和右侧列表视图中的两个相同项目。

当左侧列表视图中的任何项目更改其位置时,箭头线必须指向右侧列表视图中的同一项目。

谁能帮我解决这个问题或给我一些方法

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

1

您必须使用具有 3 个 ListView 的主要 XML,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:weightSum="1" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="0.43" >
    </ListView>

    <ListView
        android:id="@+id/listView2"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="0.14" >
    </ListView>

    <ListView
        android:id="@+id/listView3"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="0.43" >
    </ListView>

</LinearLayout>

然后,您需要一个 Row-XML,只需为 LEFT 和 RIGHT 列表视图的行填充说“row_string”,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="35dp" >
</TextView>

然后您需要一个 Image_XML,只需为中间列表视图说“row_image”,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imgv1"
    android:layout_width="wrap_content"
    android:layout_height="35dp"
    android:background="#0000ff" />

然后你将需要 ImageBean、ImageAdapter 类和 Main Activity:

ImageBean.java

public class ImageBean {
    String imgnm;
}

ImageAdapter.java

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

public class ImagesAdapter extends ArrayAdapter<ImageBean>{
    Context context;
    int resId;
    ImageBean[] imgbns;

    public ImagesAdapter(Context context, int resId, ImageBean[] imgbns) {
        super(context, resId, imgbns);
        this.context = context;
        this.resId = resId;
        this.imgbns = imgbns;
    }

    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
        View row = convertView;
        ImgHolder hldr = null;
        if(row == null)
        {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(resId, parent, false);
            hldr = new ImgHolder();
            hldr.img1 = (ImageView) row.findViewById(R.id.imgv1);
            row.setTag(hldr);
        }
        else{
            hldr = (ImgHolder)row.getTag();
        }
        hldr.img1.setImageDrawable(context.getResources().getDrawable((R.drawable.right_arrow)));
        //hldr.rImg1.setImageBitmap(readImage(imgbns[position].imgnm));
        return row;
    }

    static class ImgHolder
    {
        ImageView img1;
    }
}

YourMainActivity.java:

导入android.app.Activity;导入android.os.Bundle;导入 android.widget.ArrayAdapter;导入 android.widget.ListView;

public class HomePage extends Activity {

    ListView lv1, lv2, lv3;
    String[] strs1 = {"11", "11111", "111", "omijnu", "op", "11", "11111", "111", "omijnu", "op", "opiuyj", "abc", "bcd", "asddjjd", "omijnu", "op", "opiuyj"};
    ImageBean[] imgbns;
    //String[] strs3 = {"3333333", "33333", "333333333", "333", "3333", "3333", "333", "3333", "333333333333333333333333", "3333", "333", "333", "333", "3333", "3333333"};

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);

        lv1 = (ListView) findViewById(R.id.listView1);
        lv2 = (ListView) findViewById(R.id.listView2);
        lv3 = (ListView) findViewById(R.id.listView3);

        imgbns = new ImageBean[25];

        ImagesAdapter imgadptr = new ImagesAdapter(this, R.layout.row_image, imgbns);

        lv1.setAdapter(new ArrayAdapter<String>(this, R.layout.row_string, strs1));
        lv2.setAdapter(imgadptr);
        lv3.setAdapter(new ArrayAdapter<String>(this, R.layout.row_string, strs1));
    }
}
于 2012-07-20T13:37:32.900 回答