开发学院手机开发Android 开发 Android ScrollView的使用 阅读

Android ScrollView的使用

 2010-10-12 02:20:00 来源:本站整理   
核心提示:import android.widget.TextView;public class Test_ScrollView extends Activity {/** Called when the activity is first created. */private LinearLayout mLayout;priv

import android.widget.TextView;

public class Test_ScrollView extends Activity {

/** Called when the activity is first created. */

private LinearLayout mLayout;

private ScrollView sView;

private final Handler mHandler = new Handler();

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

// 创建一个线性布局

mLayout = (LinearLayout) this.findViewById(R.id.LinearLayout);

// 创建一个ScrollView对象

sView = (ScrollView) this.findViewById(R.id.ScrollView);

Button mBtn = (Button) this.findViewById(R.id.Button);

mBtn.setOnClickListener(mClickListener);// 添加点击事件监听

}

public boolean onKeyDown(int keyCode, KeyEvent event){

Button b = (Button) this.getCurrentFocus();

int count = mLayout.getChildCount();

Button bm = (Button) mLayout.getChildAt(count-1);

if(keyCode==KeyEvent.KEYCODE_DPAD_UP && b.getId()==R.id.Button){

bm.requestFocus();

return true;

}else if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN && b.getId()==bm.getId()){

this.findViewById(R.id.Button).requestFocus();

return true;

}

return false;

}

// Button事件监听,当点击第一个按钮时增加一个button和一个textview

private Button.OnClickListener mClickListener = new Button.OnClickListener() {

private int index = 1;

@Override

public void onClick(View v) {

TextView tView = new TextView(Test_ScrollView.this);//定义一个TextView

tView.setText("TextView" + index);//设置TextView的文本信息

//设置线性布局的属性

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(

LinearLayout.LayoutParams.FILL_PARENT,

上一页  1 2 3 4 5  下一页

Tags:Android ScrollView 使用

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接