我已经通过一个包含ImageView和TextView的xml文件并使用LayoutInflater创建了类似于listview的东西。造型自定义ListView
看来我以非常规的方式完成了这项工作,因为我无法弄清楚如何实际设计listview(理想情况下我想定义尺寸,因为还有其他内容需要放在同一个界面上)
我已经尝试在自身中设置LinearLayout样式,并将LinearLayout放在父LinearLayout中,包括名为'list'的文件中的ListView,试图在扩展ListActivity的类中定义一个setContentView。
我只想能够将自定义列表视图控件包含到LinearLayout中,就像任何其他控件一样,而不是整个UI中的控件。
public class ImageActivity extends ArrayAdapter<PlaceStore> {
private final Context context;
private final List<PlaceStore> places;
public ImageActivity(Context context, List<PlaceStore> places) {
super(context, R.layout.image_text_row, places);
this.context = context;
this.places = places;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.image_text_row, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
textView.setText(places.get(position).getName());
return rowView;
}
public class FavouriteActivity extends ListActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favourite);
FavouriteData data = new FavouriteData(this);
List<PlaceStore> pS = data.returnFileData();
setListAdapter(new ImageActivity(this, pS));
}
R.layout.image_text_row
<?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:padding="5dp" android:background="@drawable/background_type" >
<ImageView
android:id="@+id/logo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:src="@drawable/androidmarker" >
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="20sp" >
</TextView>
</LinearLayout>
您可以将列表视图放入线性布局中。然后将其项目加载到适配器中,并将适配器设置为列表视图。如果您有时间,请考虑观看此视频:[Google I/O 2010 - ListView的世界](http://youtu.be/wDBM6wVEO70)。 – 2012-07-22 10:23:39
@Ash我已经回答你的上述问题到底是你在找什么。只要给它一次尝试。为了进一步解释你可以评论我会在那里让你明白。谢谢 :) – SALMAN 2012-07-22 10:57:33