下面列出了android.widget.ProgressBar#setLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@NonNull
@Override
public FeedAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
int layoutid = tvMode ? R.layout.feed_item_tv : R.layout.feed_item;
if (viewType == TYPE_VIDEO) {
// create a new view
LinearLayout v = (LinearLayout) LayoutInflater.from(parent.getContext())
.inflate(layoutid, parent, false);
if (tvMode) {
if (Preferences.darkMode)
v.findViewById(R.id.feed_item_desc_holder).setBackgroundColor(c.getResources().getColor(R.color.transparentBlack));
v.setLayoutParams(new LinearLayout.LayoutParams(Tools.numtodp(400, c), ViewGroup.LayoutParams.WRAP_CONTENT));
} else
v.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
// set the view's size, margins, paddings and layout parameters
return new ViewHolder(v, TYPE_VIDEO);
}else {
ProgressBar pb = new ProgressBar(c);
if (tvMode)
pb.setLayoutParams(new LinearLayout.LayoutParams(Tools.numtodp(400, c), Tools.numtodp(267, c)));
return new ViewHolder(pb, TYPE_LOADER);
}
}
/**
* Ask the host application for a custom progress view to show while
* a <video> is loading.
* @return View The progress view.
*/
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
// Create a new Loading view programmatically.
// create the linear layout
LinearLayout layout = new LinearLayout(parentEngine.getView().getContext());
layout.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.setLayoutParams(layoutParams);
// the proress bar
ProgressBar bar = new ProgressBar(parentEngine.getView().getContext());
LinearLayout.LayoutParams barLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
barLayoutParams.gravity = Gravity.CENTER;
bar.setLayoutParams(barLayoutParams);
layout.addView(bar);
mVideoProgressView = layout;
}
return mVideoProgressView;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_confirm, menu);
ProgressBar pb = new ProgressBar(this);
MenuItem progressItem = menu.findItem(R.id.menu_confirm_progress);
int px = (int) (24 * Resources.getSystem().getDisplayMetrics().density);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(3*px, 3*px);
pb.setLayoutParams(lp);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
pb.setIndeterminateTintList(
ColorStateList.valueOf(0xff000000)
);
}
pb.setPaddingRelative(px, px, px, px);
progressItem.setActionView(pb);
return true;
}
/**
* First time loading of the LoaderImageView
* Sets up the LayoutParams of the view, you can change these to
* get the required effects you want
*/
private void instantiate(final Context context, final String imageUrl) {
mContext = context;
mImage = new ImageView(mContext);
mImage.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mSpinner = new ProgressBar(mContext);
mSpinner.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mSpinner.setIndeterminate(true);
addView(mSpinner);
addView(mImage);
if(imageUrl == null){
spin();
}else{
setImageDrawable(imageUrl);
}
}
private void init(Context context) {
mContext=context;
// init layout params
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
// loading progress bar
mLoading = new ProgressBar(context);
mLoading.setLayoutParams(params);
mLoading.setProgress(android.R.attr.progressBarStyleSmall);
// image view to display the bitmap
mImage = new ImageView(context);
mImage.setLayoutParams(params);
removeAllViews();
addView(mLoading);
addView(mImage);
}
public ProgressWebView(Context context, AttributeSet attrs) {
super(context, attrs);
progressbar = new ProgressBar(context, null,
android.R.attr.progressBarStyleHorizontal);
progressbar.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
10, 0, 0));
Drawable drawable = context.getResources().getDrawable(R.drawable.progress_bar_states);
progressbar.setProgressDrawable(drawable);
addView(progressbar);
// setWebViewClient(new WebViewClient(){});
setWebChromeClient(new WebChromeClient());
//是否可以缩放
getSettings().setSupportZoom(true);
getSettings().setBuiltInZoomControls(true);
}
@Override
protected void onFinishInflate() {
// Check if we have a progress indicator as a child, if not, create one
progressIndicator = findViewById(R.id.progress_indicator);
if (progressIndicator == null) {
ProgressBar pb = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleHorizontal);
pb.setIndeterminate(true);
LayoutParams lp = new LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
pb.setLayoutParams(lp);
progressIndicator = pb;
} else {
removeView(progressIndicator);
}
super.onFinishInflate();
}
@Override
/**
* Ask the host application for a custom progress view to show while
* a <video> is loading.
* @return View The progress view.
*/
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
// Create a new Loading view programmatically.
// create the linear layout
LinearLayout layout = new LinearLayout(parentEngine.getView().getContext());
layout.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.setLayoutParams(layoutParams);
// the proress bar
ProgressBar bar = new ProgressBar(parentEngine.getView().getContext());
LinearLayout.LayoutParams barLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
barLayoutParams.gravity = Gravity.CENTER;
bar.setLayoutParams(barLayoutParams);
layout.addView(bar);
mVideoProgressView = layout;
}
return mVideoProgressView;
}
/**
* Override to customize loading view, or return null if not needed.
*/
@Nullable
protected View createLoadingView() {
ProgressBar progressBar = new ProgressBar(this);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
params.gravity = Gravity.CENTER;
progressBar.setLayoutParams(params);
FrameLayout layout = new FrameLayout(this);
layout.addView(progressBar);
return layout;
}
@Override
/**
* Ask the host application for a custom progress view to show while
* a <video> is loading.
* @return View The progress view.
*/
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
// Create a new Loading view programmatically.
// create the linear layout
LinearLayout layout = new LinearLayout(this.appView.getContext());
layout.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.setLayoutParams(layoutParams);
// the proress bar
ProgressBar bar = new ProgressBar(this.appView.getContext());
LinearLayout.LayoutParams barLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
barLayoutParams.gravity = Gravity.CENTER;
bar.setLayoutParams(barLayoutParams);
layout.addView(bar);
mVideoProgressView = layout;
}
return mVideoProgressView;
}
@Override
/**
* Ask the host application for a custom progress view to show while
* a <video> is loading.
* @return View The progress view.
*/
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
// Create a new Loading view programmatically.
// create the linear layout
LinearLayout layout = new LinearLayout(parentEngine.getView().getContext());
layout.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.setLayoutParams(layoutParams);
// the proress bar
ProgressBar bar = new ProgressBar(parentEngine.getView().getContext());
LinearLayout.LayoutParams barLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
barLayoutParams.gravity = Gravity.CENTER;
bar.setLayoutParams(barLayoutParams);
layout.addView(bar);
mVideoProgressView = layout;
}
return mVideoProgressView;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ProgressBar progressBar = new ProgressBar(container.getContext());
if (container instanceof FrameLayout) {
FrameLayout.LayoutParams layoutParams =
new FrameLayout.LayoutParams(SPINNER_WIDTH, SPINNER_HEIGHT, Gravity.CENTER);
progressBar.setLayoutParams(layoutParams);
}
return progressBar;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
activity = getActivity();
aq = new AQuery(activity);
//UI
final LinearLayout linearLayout = new LinearLayout(activity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
//Progress
progressBar = new ProgressBar(activity, null, android.R.attr.progressBarStyleHorizontal);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
progressBar.setLayoutParams(layoutParams);
progressBar.setVisibility(View.GONE);
gridView = new GridView(activity);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (adapter == null) return;
ClsTrack track = (ClsTrack) adapter.getItem(position);
final String artist = track.getArtist();
ArrayList<ClsTrack> tracks = (ArrayList<ClsTrack>) FileUtils.readObject("alltracksms", activity);
ArrayList<ClsTrack> tracksFiltered = new ArrayList<ClsTrack>();
for (ClsTrack t : tracks) {
if (t.getArtist().equalsIgnoreCase(artist)) {
tracksFiltered.add(t);
}
}
((ActPlaylist) activity).close(tracksFiltered);
}
});
linearLayout.addView(progressBar);
linearLayout.addView(gridView);
return linearLayout;
}
public static ProgressBar createProgress(final Context context) {
final ProgressBar p = new ProgressBar(context);
p.setIndeterminate(true);
final RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
40, 40);
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
p.setLayoutParams(lp);
return p;
}
@Override
/**
* Ask the host application for a custom progress view to show while
* a <video> is loading.
* @return View The progress view.
*/
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
// Create a new Loading view programmatically.
// create the linear layout
LinearLayout layout = new LinearLayout(this.appView.getContext());
layout.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.setLayoutParams(layoutParams);
// the proress bar
ProgressBar bar = new ProgressBar(this.appView.getContext());
LinearLayout.LayoutParams barLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
barLayoutParams.gravity = Gravity.CENTER;
bar.setLayoutParams(barLayoutParams);
layout.addView(bar);
mVideoProgressView = layout;
}
return mVideoProgressView;
}
static View getProgressWaitingItem() {
ProgressBar cslp_progress_bar_waiting = new ProgressBar(G.context);
cslp_progress_bar_waiting.setId(R.id.cslp_progress_bar_waiting);
cslp_progress_bar_waiting.setPadding(i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4));
cslp_progress_bar_waiting.setVisibility(View.VISIBLE);
FrameLayout.LayoutParams layout_842 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layout_842.gravity = Gravity.CENTER;
cslp_progress_bar_waiting.setIndeterminate(true);
cslp_progress_bar_waiting.setLayoutParams(layout_842);
return cslp_progress_bar_waiting;
}
private void init(Context context) {
setBackgroundColor(WXResourceUtils.getColor("#ee000000"));
mProgressBar = new ProgressBar(context);
FrameLayout.LayoutParams pLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
mProgressBar.setLayoutParams(pLayoutParams);
pLayoutParams.gravity = Gravity.CENTER;
addView(mProgressBar);
getViewTreeObserver().addOnGlobalLayoutListener(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ProgressBar progressBar = new ProgressBar(container.getContext());
if (container instanceof FrameLayout) {
FrameLayout.LayoutParams layoutParams =
new FrameLayout.LayoutParams(SPINNER_WIDTH, SPINNER_HEIGHT, Gravity.CENTER);
progressBar.setLayoutParams(layoutParams);
}
return progressBar;
}
@Override
/**
* Ask the host application for a custom progress view to show while
* a <video> is loading.
* @return View The progress view.
*/
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
// Create a new Loading view programmatically.
// create the linear layout
LinearLayout layout = new LinearLayout(this.appView.getContext());
layout.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.setLayoutParams(layoutParams);
// the proress bar
ProgressBar bar = new ProgressBar(this.appView.getContext());
LinearLayout.LayoutParams barLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
barLayoutParams.gravity = Gravity.CENTER;
bar.setLayoutParams(barLayoutParams);
layout.addView(bar);
mVideoProgressView = layout;
}
return mVideoProgressView;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context context = mReactContext;
LayoutParams rootViewLayoutParams = this.getFullscreenLayoutParams(context);
RelativeLayout rootView = new RelativeLayout(context);
mProgressBar = new ProgressBar(context);
RelativeLayout.LayoutParams progressParams = new RelativeLayout.LayoutParams(convertDpToPixel(50f,context),convertDpToPixel(50f,context));
progressParams.addRule(RelativeLayout.CENTER_IN_PARENT);
mProgressBar.setLayoutParams(progressParams);
mProgressBar.setIndeterminate(true);
getDialog().setCanceledOnTouchOutside(true);
rootView.setLayoutParams(rootViewLayoutParams);
// mWebView = (AdvancedWebView) rootView.findViewById(R.id.webview);
Log.d(TAG, "Creating webview");
mWebView = new AdvancedWebView(context);
// mWebView.setId(WEBVIEW_TAG);
mWebView.setListener(this, this);
mWebView.setVisibility(View.VISIBLE);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
LayoutParams layoutParams = this.getFullscreenLayoutParams(context);
//new LayoutParams(
// LayoutParams.FILL_PARENT,
// DIALOG_HEIGHT
// );
// mWebView.setLayoutParams(layoutParams);
rootView.addView(mWebView, layoutParams);
rootView.addView(mProgressBar,progressParams);
// LinearLayout pframe = new LinearLayout(context);
// pframe.setId(WIDGET_TAG);
// pframe.setOrientation(LinearLayout.VERTICAL);
// pframe.setVisibility(View.GONE);
// pframe.setGravity(Gravity.CENTER);
// pframe.setLayoutParams(layoutParams);
// rootView.addView(pframe, layoutParams);
this.setupWebView(mWebView);
mController.getRequestTokenUrlAndLoad(mWebView);
Log.d(TAG, "Loading view...");
return rootView;
}