0
我有滾動視圖和表格佈局,行表。如何爲scoll視圖設置X Y和hight寬度
現在我想爲xml中的每一個編程代碼設置X和Y邊距以及高和寬。
請注意,我爲此活動使用絕對佈局。
這是我的活動全碼:
公共類ListActivity延伸活動{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
AbsoluteLayout ff = (AbsoluteLayout) this.findViewById(R.id.AbsoluteLayout1);
TableLayout tl = new TableLayout(this);
TableRow tr = new TableRow(this);
TextView tv = new TextView(this);
ScrollView myScrollView = new ScrollView(this);
// adding scrollview to current layout
ff.addView(myScrollView);
// adding TableLayout to current myScrollView
myScrollView.addView(tl);
/* not working
ViewGroup.LayoutParams lp = new LayoutParams(100 ,100);
myScrollView.setLayoutParams(lp);*/
myScrollView.setPadding(0, 210, 120, 0);
/* not working
LayoutParams layoutParams = new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
myScrollView.setLayoutParams(layoutParams); */
tr.addView(tv);
tv.setText("gewgewg");
tv.addView(tr);
}
}
android.view.ViewGroup $的LayoutParams不能轉換到android.widget.AbsoluteLayout $的LayoutParams – user1714553 2013-03-03 18:01:22
是,這部作品在線性佈局的情況下,罰款。 – ridoy 2013-03-04 17:44:48
LayoutParams.FILL_PARENT現在已被棄用,以支持LayoutParams.MATCH_PARENT – 2017-02-12 16:23:36