我有一个带有一些片段的TabWidget。我想在其中显示ProgressBar,但ProgressBar从未显示过。这是我的代码:
private ProgressBar progressBar;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.roomstatusadmin_activity, container, false);
progressBar = new ProgressBar(getActivity().getApplicationContext(), null, android.R.attr.progressBarStyleSmall);
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.VISIBLE);
//FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//layoutParams.gravity = Gravity.CENTER;
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
progressBar.setLayoutParams(layoutParams);
return view;
}
我读了一些问题,但没有解决方案,例如this。我测试时将ProgressBar添加到我的layout.xml中,并显示ProgressBar。但我会在一些布局中使用这个ProgressBar,所以我真的需要它以编程方式。
答案 0 :(得分:2)
您尚未将进度条添加到片段的布局中。
将布局xml膨胀并转换为其根视图。如果您的根视图是RelativeLayout,那么:
$("#checkAll").click(function(){
if($('#default-select option:selected').val() == 'sent'){
$('#testTable tbody input[type="checkbox"]').prop('checked', this.checked);
}});
现在将进度条添加到布局:
RelativeLayout view = (RelativeLayout)inflater.inflate(R.layout.roomstatusadmin_activity, container, false);
答案 1 :(得分:1)
您正在创建一个进度条而不是附加到视图。要将其附加到frgament视图,请找到该段的父布局的ID。
YOURPARENTLAYOUT layout=(YOURPARENTLAYOUT)view.findViewById(R.id.yourParentLayout)
在创建进度条后将其添加到父布局
layout.addView(progressBar);