gpt4 book ai didi

java - 如何以编程方式在布局中居中进度条?

转载 作者:行者123 更新时间:2023-11-29 22:25:37 26 4
gpt4 key购买 nike

我想以编程方式在代码中居中我的进度条。这是我的代码:

  LinearLayout streamLayout = new LinearLayout(this);
streamLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
streamLayout.setOrientation(LinearLayout.VERTICAL);
streamLayout.setGravity(Gravity.CENTER);

LinearLayout newsLayout = new LinearLayout(this);
streamLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
streamLayout.setOrientation(LinearLayout.VERTICAL);
streamLayout.setGravity(Gravity.CENTER);

mSwipeView.addView(streamLayout);
mSwipeView.addView(newsLayout);
mSwipeView.addView(new LinearLayout(this));

((LinearLayout) mSwipeView.getChildContainer().getChildAt(0)).addView(streamListView);
((LinearLayout) mSwipeView.getChildContainer().getChildAt(0)).addView(streamProgressBar);
((LinearLayout) mSwipeView.getChildContainer().getChildAt(1)).addView(newsListView);
((LinearLayout) mSwipeView.getChildContainer().getChildAt(1)).addView(newsProgressBar);
((LinearLayout) mSwipeView.getChildContainer().getChildAt(2)).addView(chartImageView);

如何让进度条在我的布局中垂直居中,水平居中?

最佳答案

尝试使用 LinearLayout.layoutParams 并将它们设置到 View 。它们包含一个场重力,您可以将其设置为 Gravity.CENTER 或类似的。

See This Link

关于java - 如何以编程方式在布局中居中进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6045295/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com