Android 启动时未显示progressbar
根据一些书,我设置了以下内容。但在加载应用程序时仍无法看到进度条 MainActivity.javaAndroid 启动时未显示progressbar,android,progress-bar,Android,Progress Bar,根据一些书,我设置了以下内容。但在加载应用程序时仍无法看到进度条 MainActivity.java public class MainActivity extends AppCompatActivity implements View.OnClickListener { private EditText et; private ImageView iv; private ProgressBar pb; @Override protected void onCreate(Bundle sav
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private EditText et;
private ImageView iv;
private ProgressBar pb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button)findViewById(R.id.button);
et = (EditText) findViewById(R.id.edittext);
b.setOnClickListener(this);
iv = (ImageView)findViewById(R.id.image);
pb = (ProgressBar)findViewById(R.id.progressbar);
pb.setVisibility(View.VISIBLE);
}
@Override
public void onClick(View v){
switch(v.getId()){
case R.id.button:
//String input = et.getText().toString();
//Toast.makeText(MainActivity.this, input,Toast.LENGTH_SHORT).show(); //**
//pb.setVisibility(View.VISIBLE);
break;
default:
break;
}
}
还有我的activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text_view"
android:text="This is a text"
android:gravity="center"
android:textSize="24sp"
android:textColor="#00ff00"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button"
android:textAllCaps="false"
android:id="@+id/button"
/>
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type sth here :)"
android:maxLines="2"
/>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/rose"
/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressbar"
android:indeterminate="true"
android:layout_centerInParent="true"
/>
</LinearLayout>
我引用了此链接:但在我的例子中仍然不起作用…该栏只是不显示而已…您的根布局是LinearLayout。
android:layout\u centerInParent
不是LinearLayout子级的属性。因此,如果您想在中间显示“ProgressBar”,最好使用相对布局作为父级
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="This is a text"
android:textColor="#00ff00"
android:textSize="24sp" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button"
android:textAllCaps="false" />
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type sth here :)"
android:maxLines="2"
/>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/rose" />
</LinearLayout>
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true" />
</RelativeLayout>
可能的原因是您在“开发人员选项”中关闭了动画。 我在测试项目中使用您的布局文件。进度条将显示,并正常工作。
关闭动画使进度条不可见。奇怪。在xml文件的末尾应该是“”,我试图添加到上面,但不知怎么的,它没有显示出来。啊…为什么不投票呢??令人沮丧的是…我认为这个问题很有帮助,因为它的独特性足以将它与同类区别开来…StackOverflow应该对投票人有更严格的控制,比如说,当你投票时,就像理性一样…它是有效的!!非常感谢!即使在我没有使用“android:layout\u centerInParent”时,它也不起作用。但是这个解决方案是有效的,坚持下去是明智的。非常感谢@ADM,你解决了我的头痛!我已经在我的三星手机上打开了所有与动画相关的功能,但它对我不起作用。或者,你是说我必须在android studio中打开一些动画功能?