我认为在 ScrollView 中使用 ListView 不是一件好事如果您希望该图像也应该滚动而不是这样:
1)对于 Listview,您需要一个自定义适配器 ,其中在自定义适配器类的getview()方法中,您必须像这样
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.listview_rowlayout, parent, false);
TextView textview = (TextView) row.findViewById(R.id.tv_list);
ImageView imageview = (ImageView) row.findViewById(R.id.iv_list);
textview.setText(data_text[position]);
if(position==0){
imageview.setImageResource(R.drawable.YourimageName);
}else{
imageview.setVisibility(View.GONE);
}
return (row);
}
你的listview_rowlayout.xml是这样的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<ImageView
android:id="@+id/iv_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParenttop="true"
android:layout_marginLeft="10dp"
/>
<TextView
android:id="@+id/tv_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#000000"
android:layout_alignBottom="@+id/imageView1"
android:text="" />
</RelativeLayout>
并且您在其中添加了 listview 的main.xml应该是这样的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="true" />
</RelativeLayout>