private void init() { // TODO Auto-generated method stub // 线性布局 LinearLayout layout = new LinearLayout(this); // 设置布局 水平方向 layout.setOrientation(LinearLayout.HORIZONTAL); // 进度条 progressBar = new ProgressBar(this); // 进度条显示位置 progressBar.setPadding(0, 0, 15, 0); // 把进度条加入到layout中 layout.addView(progressBar, mLayoutParams); // 文本内容 TextView textView = new TextView(this); textView.setText("加载中..."); textView.setGravity(Gravity.CENTER_VERTICAL); // 把文本加入到layout中 layout.addView(textView, FFlayoutParams); // 设置layout的重力方向,即对齐方式是 layout.setGravity(Gravity.CENTER); // 设置ListView的页脚layout loadingLayout = new LinearLayout(this); loadingLayout.addView(layout, mLayoutParams); loadingLayout.setGravity(Gravity.CENTER); // 得到一个ListView用来显示条目 listView = (ListView) findViewById(R.id.tv); // 添加到脚页显示 listView.addFooterView(loadingLayout); // 给ListView添加适配器 listView.setAdapter(adapter); // 给ListView注册滚动监听 listView.setOnScrollListener(this); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Find Views mListView = (ListView) findViewById(R.id.listView1); /** 用mLinear做为load-progress的容器。 */ LinearLayout mLinear = new LinearLayout(this); mLinear.setOrientation(LinearLayout.HORIZONTAL); mProgressBar = new ProgressBar(this); mProgressBar.setPadding(0, 0, 15, 0); mLinear.addView(mProgressBar, WClayoutParams); TextView textView = new TextView(this); textView.setText("加载中..."); textView.setGravity(Gravity.CENTER_VERTICAL); mLinear.addView(textView, FFlayoutParams); mLinear.setGravity(Gravity.CENTER); registerForContextMenu(mListView); // 将load-progress加进ListView的最底行 mListView.addFooterView(mLinear); mAdapter = new PageAdapter(); mListView.setAdapter(mAdapter); mListView.setOnScrollListener(this); }
private void showLoading() { ProgressBar pb = new ProgressBar(getContext()); pb.setIndeterminateDrawable(getContext().getResources().getDrawable(R.drawable.progress)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); pb.setPadding(0, (int) (50 * ratio), 0, (int) (50 * ratio)); pb.setLayoutParams(params); pb.setId(5000); TableLayout table = (TableLayout) findViewById(R.id.table); table.setGravity(Gravity.CENTER); table.addView(pb); }
// shared image container private RelativeLayout getThumbView() { rlThumb = new RelativeLayout(getContext()); rlThumb.setId(1); int dp_82 = dipToPx(getContext(), 82); int dp_98 = dipToPx(getContext(), 98); LayoutParams lpThumb = new LayoutParams(dp_82, dp_98); rlThumb.setLayoutParams(lpThumb); ivImage = new ImageView(getContext()); int resId = getBitmapRes(activity, "ssdk_oks_btn_back_nor"); if (resId > 0) { ivImage.setBackgroundResource(resId); } ivImage.setScaleType(ScaleType.CENTER_INSIDE); ivImage.setImageBitmap(image); int dp_4 = dipToPx(getContext(), 4); ivImage.setPadding(dp_4, dp_4, dp_4, dp_4); int dp_74 = dipToPx(getContext(), 74); RelativeLayout.LayoutParams lpImage = new RelativeLayout.LayoutParams(dp_74, dp_74); int dp_16 = dipToPx(getContext(), 16); int dp_8 = dipToPx(getContext(), 8); lpImage.setMargins(0, dp_16, dp_8, 0); ivImage.setLayoutParams(lpImage); ivImage.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (image != null && !image.isRecycled()) { PicViewer pv = new PicViewer(); pv.setImageBitmap(image); pv.show(activity, null); } } }); rlThumb.addView(ivImage); int dp_24 = dipToPx(getContext(), 24); progressBar = new ProgressBar(getContext()); progressBar.setPadding(dp_24, dp_24, dp_24, dp_24); RelativeLayout.LayoutParams pb = new RelativeLayout.LayoutParams(dp_74, dp_74); pb.setMargins(0, dp_16, dp_8, 0); progressBar.setLayoutParams(pb); rlThumb.addView(progressBar); Button btn = new Button(getContext()); btn.setOnClickListener( new OnClickListener() { public void onClick(View v) { // remove the photo to share rlThumb.setVisibility(View.GONE); ivPin.setVisibility(View.GONE); removeImage(imgInfo); } }); resId = getBitmapRes(activity, "ssdk_oks_img_cancel"); if (resId > 0) { btn.setBackgroundResource(resId); } int dp_20 = dipToPx(getContext(), 20); RelativeLayout.LayoutParams lpBtn = new RelativeLayout.LayoutParams(dp_20, dp_20); lpBtn.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); lpBtn.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); btn.setLayoutParams(lpBtn); rlThumb.addView(btn); if (!haveImage()) { rlThumb.setVisibility(View.GONE); } return rlThumb; }