scrollview和listview滚动冲突简单解决办法。。。

在网上看了看资料感觉,滚动冲突问题,如果不想太复杂的话。其实这个可以用一下,但是点击事件我没想出来怎么处理。我会继续跟进这个东西的

item.xml代码

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="wrap_content"
 5     android:background="#ffffff"
 6     android:orientation="vertical" >
 7     
 8     <LinearLayout 
 9     android:layout_width="fill_parent"
10     android:layout_height="wrap_content"
11     android:orientation="horizontal">
12         <TextView android:layout_width="wrap_content"
13             android:layout_height="wrap_content"
14             android:id="@+id/name_TV"
15             android:layout_weight="1"
16             android:text="张强"/>
17         
18           <TextView android:layout_width="wrap_content"
19             android:layout_height="wrap_content"
20             android:layout_weight="1"
21             android:id="@+id/title_TV"
22             android:text="标题"/>
23     </LinearLayout>
24     
25     <TextView android:layout_width="fill_parent"
26         android:layout_height="wrap_content"
27         android:layout_marginTop="30dip"
28         android:id="@+id/message_TV"
29         android:text="9999999999999999999999999999999"/>
30     
31     <TextView android:layout_width="fill_parent"
32             android:layout_height="wrap_content"
33             android:text="................................................................................"/>
34 
35 </LinearLayout>
 
  

 


main.xml代码
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="fill_parent"
 4     android:layout_height="fill_parent" >
 5 
 6     
 7       <LinearLayout
 8         xmlns:android="http://schemas.android.com/apk/res/android"
 9         android:layout_width="fill_parent"
10         android:layout_height="fill_parent"
11         android:orientation="vertical" >    
12              
13          <TextView  android:layout_width="fill_parent"
14              android:layout_height="wrap_content"
15              android:id="@+id/text_TV"
16              android:paddingLeft="20dip"
17              android:paddingRight="20dip"
18              android:text="9999999999999999999999999999999999999999999999"
19              />
20          
21          <TableLayout android:layout_width="wrap_content"
22              android:layout_height="wrap_content"
23               android:background="@drawable/itemcolor"
24              android:id="@+id/table_LV">
25              
26          </TableLayout>
27             <Button android:layout_width="fill_parent"
28             android:layout_height="match_parent"
29             android:id="@+id/click_bt"
30             android:text="加载更多"
31             />
32          
33          </LinearLayout>
34          
35 
36 </ScrollView>
 
  

 

java代码
1
package com.peng.listviewandscroll; 2 3 import java.lang.reflect.Array; 4 import java.util.ArrayList; 5 6 import android.R.array; 7 import android.app.Activity; 8 import android.app.SearchManager.OnCancelListener; 9 import android.content.Context; 10 import android.os.AsyncTask; 11 import android.os.Bundle; 12 import android.view.View; 13 import android.view.View.OnClickListener; 14 import android.widget.ArrayAdapter; 15 import android.widget.Button; 16 import android.widget.CheckBox; 17 import android.widget.LinearLayout; 18 import android.widget.ListView; 19 import android.widget.TableLayout; 20 import android.widget.TextView; 21 22 public class ListviewandScroviewActivity extends Activity implements OnClickListener{ 23 private ArrayList<String> arrays; 24 private TableLayout table; 25 private Context mContext; 26 private task task; 27 28 29 /** Called when the activity is first created. */ 30 @Override 31 public void onCreate(Bundle savedInstanceState) { 32 super.onCreate(savedInstanceState); 33 setContentView(R.layout.main); 34 table = (TableLayout) this.findViewById(R.id.table_LV); 35 TextView tv = (TextView) this.findViewById(R.id.text_TV); 36 Button bt = (Button) this.findViewById(R.id.click_bt); 37 bt.setOnClickListener(this); 38 arrays = new ArrayList<String>(); 39 mContext = this; 40 task = new task(); 41 task.execute(); 42 } 43 44 45 class task extends AsyncTask<Object, Object, Integer> { 46 47 @Override 48 protected Integer doInBackground(Object... params) { 49 try { 50 arrays.add("1123"); 51 arrays.add("你好啊"); 52 arrays.add("哈哈哈哈"); 53 Thread.sleep(3000); 54 } catch (InterruptedException e) { 55 // TODO Auto-generated catch block 56 e.printStackTrace(); 57 } 58 return null; 59 } 60 61 @Override 62 protected void onPostExecute(Integer result) { 63 // TODO Auto-generated method stub 64 for(String s : arrays) { 65 LinearLayout LL = (LinearLayout) View.inflate(mContext, R.layout.item, null); 66 TextView tv = (TextView) LL.findViewById(R.id.name_TV); 67 tv.setText(s); 68 table.addView(LL); 69 } 70 71 super.onPostExecute(result); 72 } 73 } 74 75 @Override 76 public void onClick(View v) { 77 // TODO Auto-generated method stub 78 task = new task(); 79 task.execute(); 80 } 81 }

 

转载于:https://www.cnblogs.com/smart-bear/p/3456553.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值