zoukankan      html  css  js  c++  java
  • /Users/alamps/AndroidStudioProjects/Demo10ScrollView

    1.define xml
    
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
                >
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:tools="http://schemas.android.com/tools"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:id="@+id/linearView"
                  android:orientation="vertical"
                  android:paddingLeft="@dimen/activity_horizontal_margin"
                  android:paddingRight="@dimen/activity_horizontal_margin"
                  android:paddingTop="@dimen/activity_vertical_margin"
                  android:paddingBottom="@dimen/activity_vertical_margin"
                  tools:context=".MainActivity">
    
    </LinearLayout>
    
    
    </ScrollView>
    
    
    2. code
    
    
    
    package com.example.demo10scrollview;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.ViewGroup;
    import android.widget.Button;
    import android.widget.LinearLayout;
    
    public class MainActivity extends Activity {
    
        private String data[]={"www.csdn.com","www.baidu.com","wwww.alamps.com","www.iteye.com","www.google.com","www.qq.com"};
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            //定义第二层LinearLayout
            LinearLayout linearLayout=(LinearLayout)super.findViewById(R.id.linearView);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            for (int i=0;i<this.data.length;i++){
                Button button = new Button(this);
                button.setText(this.data[i]);
                linearLayout.addView(button,params);
    
            }
        }
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
        
    }
  • 相关阅读:
    【JavaScript】关于javascript原型的深入理解
    【JavaScript】关于JS中的constructor与prototype
    【JavaScript】关于prototype
    【JavaScript】重温Javascript继承机制
    【JavaScript】新浪微博ajax请求后改变地址栏url,但页面不跳转的方案解析
    【JavaScript】JavaScript函数的参数
    【JavaScript】页面加载性能优化
    HTML5 修改浏览器url而不刷新页面
    【339】matplotlib based on python3
    【338】Pandas.DataFrame
  • 原文地址:https://www.cnblogs.com/alamps/p/5259631.html
Copyright © 2011-2022 走看看