主界面 main.xml
<ImageView android:id="@+id/img1"
android:layout_width="fill_parent"
android:layout_height="148dip"
android:layout_marginTop="0dip"
android:scaleType="fitXY"
/>
<ListView
android:id="@+id/listView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:scrollbars="vertical"
android:background="#ffffff"
android:divider="#aaaaaa"
android:dividerHeight="1px"/>
listview子界面
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="24dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="2dip"
android:textSize="18px"
android:singleLine="true"
android:textColor="#333333" />
<TextView
android:id="@+id/navinfo"
android:layout_width="wrap_content"
android:layout_height="36dip"
android:textSize="14px"
android:textColor="#888888" />
现界面可正常运行,在滚动listview中记录时,img1这块不会滚动,
现需:在滚动listview中记录时,img1也要随界面一起滚动,如何实现呀,thanks
------解决方案--------------------
把imageview放到listview第一行,在BaseAdapter的getView判断下是第一行的话显示图片,其他显示正常布局。
------解决方案--------------------
用帧布局吧,listview写在上面,imageview写在下面覆盖住顶端即可
------解决方案--------------------
你把imageView放在main.xml 没放在listView指定控件布局xml中 listView当然没imageVIEW 更不用说滚动了吧
------解决方案--------------------
呵呵不好意思 我就知道这些 自己也没有实现过 初学
------解决方案--------------------
你的意思是说 ImageView android:id="@+id/img1" 要随着listview 的滚动而 滚动?还是说..
你的img1要一直出现在界面.
------解决方案--------------------
------解决方案--------------------
public View getView(int position, View view, ViewGroup parent) {
if(view == null){
view = getLayoutInflater().inflate(R.layout.news_list_item, null);
}
//新闻标题
TextView tvTitle = (TextView)view.findViewById(R.id.title);
tvTitle.setText(newsItems.get(position).getTitle());
//新闻内容
TextView tvContent = (TextView)view.findViewById(R.id.navinfo);
tvContent.setText(newsItems.get(position).getNavinfo());
return view;
}
positon是0的时候换成你想要的布局 行不?
------解决方案--------------------
对listview的子布局部分建两个布局文件,根据position的值来判断使用哪个,position为0的时候用第一个,不为0的时候用第二个,下面是测试代码
public class Test_0209Activity extends Activity {
private String items[] = {"a","b","c","d","e","f","g","h","i","j","k"};
private ListView lv = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv = (ListView)findViewById(R.id.listView1);
lv.setAdapter(new MyAdapter());
}
class MyAdapter extends BaseAdapter{