-1

带有第一行左侧图像和右侧文本的 android listview,第二行与第一行正好相反。任何人都可以帮我提供示例代码吗?或者它可能在 listview 中吗?

4

1 回答 1

1

我们做如下替代项目

    row.xml
    <RelativeLayout>
    <ImageView
    android:visibility="gone"
    android:id="@+id/img1"
    android:layout_alignParentLeft="true"
    />
    <TextView
    android:id="@+id/txt1"
    android:layout_alignParentLeft="true"
    />
    <ImageView
    android:id="@+id/img2"
    android:layout_alignParentRight="true"
    />
    <TextView
    android:id="@+id/txt1"
    android:layout_alignParentRight="true"
    android:visibility="gone"
    />
    </RelativeLayout>

//In Adapter
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    if(position%2==0)
    {
    //left side image and right side text
    img2.setImgResource();
    img2.setVisibility(VIEW.GONE);
    txt2.setVisibility(VIEW.GONE);
    img1.setVisibility(VIEW.VISABLE);
    txt1.setVisibility(VIEW.VISABLE);
    txt2.setText();
    }
    else
    {
    //left side text and right side image code

    img2.setImgResource();
    img1.setVisibility(VIEW.GONE);
    txt1.setVisibility(VIEW.GONE);
    img2.setVisibility(VIEW.VISABLE);
    txt2.setVisibility(VIEW.VISABLE);
    txt2.setText();
    }
    }
于 2012-07-05T11:03:19.233 回答