android programing3.2.5
昨天那上面东西太多,今天再从新开个项目,老办法新建个项目,然后把activity_main.xml文件修改为:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="60dp"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button"/>
</LinearLayout>
然后把mainactivity.java修改为:
package com.example.xinwei.viewcontroller2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
private Button button;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
makeProgressBarMove();
}
private void makeProgressBarMove() {
button = (Button)findViewById(R.id.button);
progressBar =(ProgressBar)findViewById(R.id.progress_bar);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int progress=progressBar.getProgress();
progressBar.incrementProgressBy(5);
if(progress==100){
progressBar.setVisibility(View.GONE);
}
}
});
}
}
效果图:
页:
[1]