2012-08-24 224 views
1

我有一个扩展了View的类。我想以编程方式将它添加到ScrollView。我可以将它添加到LinearLayout,但没有成功,因为ScrollView。是什么赋予了?将视图添加到滚动视图

sv = (ScrollView)findViewById(R.id.sv); 

myview = new MyViewClass(this); 
myview.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 

sv.addView(myview); 
+0

你在调用setContentView(sv); ? –

+0

不,我打电话setContentView(R.layout.main)其中包含滚动视图 – bwoogie

回答

1

您可以将您的视图添加到滚动查看if its the only view in the ScrollView

否则您将获得ScrollView can have only 1 direct child例外。

将多个视图添加到滚动视图。首先在ScrollView中添加线性或相对布局,然后将视图添加到此布局。

0
jsonUserInfo = actionObject.getUserInfoID(urlsId).getJSONArray("data").getJSONObject(i); 
ModeUser userinf=new ModeUser(); 
userinf.Male=jsonUserInfo.getString("sex"); 
userinf.userName=jsonUserInfo.getString("first_name"); 
userinf.UserLastName=jsonUserInfo.getString("last_name"); 
UserInfoDatInList.add(userinf); 
相关问题