Android中scrollview

下面是scollView的处理

import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class MainActivity extends Activity {
	//下面适应简单的scroll_view
	private String data[]={"mldn","lixinaghua"};
	private String s[];

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		LinearLayout layout =(LinearLayout)super.findViewById(R.id.meliner);
		LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(
				ViewGroup.LayoutParams.FILL_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		Map< String, String> param=new HashMap();
		//把数据封装起来,放到param里面
			param.put("name",data[0]);
			param.put("author",data[1]);
			String str=editData(param).toString();//可以把数据转化成String
			System.out.println(str);
			for(int x=0;x<10;x++){
				 s[x]=(String) str;
				 Button but=new Button(this);
				 but.setText(this.s[x]);
				 layout.addView(but,params);				 
			}
	}
	public StringBuffer editData( Mapparam){
		StringBuffer buf=new StringBuffer();
		//对数据进行处理,
				for(Map.Entryentry:param.entrySet()){
					buf.append(entry.getKey());
					buf.append("=");
					buf.append(entry.getValue());
				}
				return buf;
	}
}
				
				


你可能感兴趣的:(Andriod开发)