通过代码程序实现 添加多个按钮
?
?如下图我想一次添加多个 seekbar,但是family呢只出现一个,怎么才能实现第一章图的情况呢。
?mymain.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:scrollbars="vertical"> <LinearLayout android:orientation="vertical" android:id="@+id/myMainLayout" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Family" android:id="@+id/Family" android:textSize="16px" android:padding="5px" android:textStyle="bold" android:gravity="center_horizontal"></TextView> </LinearLayout> </ScrollView>
?
另一个?xml (myviews.xml),
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold" android:id="@+id/Module" android:text="Location"> </TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="context_notion_level_off" android:layout_alignRight="@+id/Module" android:id="@+id/ContextNotionLevel"> </TextView> <SeekBar android:layout_height="wrap_content" android:id="@+id/SeekBar01" android:layout_width="fill_parent" android:padding="5px" android:saveEnabled="true" android:layout_below="@+id/Module" android:max="2"> </SeekBar> </RelativeLayout>
?
super.onCreate(savedInstanceState); setContentView(R.layout.mymain); LinearLayout l = (LinearLayout) findViewById(R.id.myMainLayout); LayoutInflater linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); for(int i = 0 ; i < 15; i++) { View myView = linflater.inflate(R.layout.myviews, null); SeekBar s = (SeekBar) myView.findViewById(R.id.SeekBar01); //表明哪一个被使用 s.setId(i); TextView t = (TextView) myView.findViewById(R.id.Module); // 动态修改文字 t.setText(("My location " + i).toString()); s.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){ @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { Log.i("=========","My SeekBar = " + seekBar.getId()); Log.i("=========","My Progress = " + progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub }}); l.addView(myView);
?