나는 구조가 있다고 가정 당신이 설명하는 ListView 항목의 내용을 말합니다. 개별 항목의 레이아웃을 정의하여이 작업을 수행 할 수 있습니다. 아래 코드는 비슷한 상황에서 저에게 효과적입니다.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:padding="6dip" android:layout_height="?android:attr/listPreferredItemHeight">
<ImageView
android:id="@+id/result_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:src="@drawable/image1"/>
<TextView
android:id="@+id/result_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/result_icon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:text="Title" />
<TextView
android:id="@+id/result_second_line"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_toRightOf="@id/result_icon"
android:layout_below="@id/result_name"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Second line" />
</RelativeLayout>
그런 다음 ListActivity와 함께 사용하려면 BaseAdapter를 확장해야합니다. 레이아웃을 확장하고 RSS 피드의 데이터로 채워야합니다.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Result result = this.results.get(position);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout view = (RelativeLayout)
inflater.inflate(R.layout.result_item, null, false);
ImageView image = (ImageView) view.findViewById(R.id.result_icon);
image.setImageResource(result.imageResource);
TextView name = (TextView) view.findViewById(R.id.result_name);
name.setText(result.location);
TextView secondLine = (TextView) view.findViewById(R.id.result_second_line);
secondLine.setText(result.shortDescription);
return view;
}
덕분에이 내가 RelativeLayout의 파일이 아마 프로젝트/고해상도/레이아웃 result_item.xml로 저장하고 있음을 유의 –
도움이되었다 / –