ScrollView动态加载控件问题

cymIT 2011-02-21 02:47:34
如何实现点击左侧的图片后在右边ScrollView里动态添加个textView;图片如下
http://hi.csdn.net/space-4633322-do-album-picid-745941.html

这是oneTab的java代码:用来加载tab的内容页面的
public class OneTab extends Activity implements OnTouchListener {
/** Called when the activity is first created. */
int count=0;
long firClick;
long secClick;
TextView textView;
private LinearLayout mLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.onetabgridview);

mLayout=(LinearLayout)findViewById(R.id.layout);
// 取得GridView对象
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setFocusableInTouchMode(true);
// 添加元素给gridview
gridview.setAdapter(new ImageAdapter(this));
// 设置gridview的背景
gridview.setBackgroundResource(R.drawable.bg);
//gridView双击事件
gridview.setOnTouchListener(this);

}
@Override
public boolean onTouch(View v, MotionEvent event) {
//双击事件
if(MotionEvent.ACTION_DOWN == event.getAction()){
count++;
if(count == 1){
firClick = System.currentTimeMillis();

} else if (count == 2){
secClick = System.currentTimeMillis();
if(secClick - firClick < 1000){
textView=new TextView(this);
textView.setText("aaaaaaaaaaaaa");
//双击事件,动态给scroolView增加控件
//设置线性布局的属性
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);

mLayout.addView(textView,params);
}
count = 0;
firClick =0;
secClick =0;
}
}
return true;
}
}
...全文
2318 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cymIT 2011-02-22
  • 打赏
  • 举报
回复
我要添加的控件是另一个页面(Dinning.xml)的scroolView下的.而oneTab只是Dinning.xml页面的tabwidget中的一个tab子布局页面.相当与在tabhost的子页面中通过双击,动态添加控件到dinning页面的sroolview中
iampy 2011-02-22
  • 打赏
  • 举报
回复

textViewLeft = (TextView) findViewById(R.id.tv111);
rightLayout = (LinearLayout) findViewById(R.id.rightView);

textViewLeft.setOnTouchListener(this);

其他代码没变。
iampy 2011-02-22
  • 打赏
  • 举报
回复
用你的代码,我把左边的GridView换成一般的TextView,可以实现左边双击,在右边动态添加TextView的功能。
简化了界面布局,原理应该是一样的吧,XML如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHostLayout"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/tv111"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="双击在右边添加TextView"
/>
<LinearLayout
android:id="@+id/rightView"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_toRightOf="@+id/tv111"
>
</LinearLayout>
</RelativeLayout>

iampy 2011-02-21
  • 打赏
  • 举报
回复
你的onTouch里面写的mLayout.addView(textView,params);
不是往列表里面添加一条记录吗?
cymIT 2011-02-21
  • 打赏
  • 举报
回复
没人吗?自己顶下

80,359

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧