关于android控件的应用!求解 高分奉上!
packagecom.cn;importandroid.app.Activity;importandroid.content.res.Resources;importan...
package com.cn;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
public class Test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);
/*Button bn1 = (Button)findViewById(R.id.bn1);
Button bn2 = (Button)findViewById(R.id.bn2);
bn1.setText("");
bn2.setText("");
bn1.setBackgroundColor(Color.RED);
bn2.setBackgroundResource(R.drawable.exit1);
Resources re= getResources();
Drawable dr = re.getDrawable(R.drawable.icon);
bn1.setBackgroundDrawable(dr);
ImageView im = (ImageView)findViewById(R.id.ImageView01);
ImageButton imb = (ImageButton)findViewById(R.id.ImageButton01);
im.setImageResource(R.drawable.exit1);
imb.setImageDrawable(dr);
final Animation ani = AnimationUtils.loadAnimation(this, R.anim.anim);
bn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.startAnimation(ani);
}
});
RadioButton rb = (RadioButton)findViewById(R.id.RadioButton01);
rb.setBackgroundColor(Color.BLACK);
rb.setBackgroundResource(R.drawable.icon);
RadioGroup rg = (RadioGroup)findViewById(R.id.RadioGroup01);
rg.setBackgroundColor(Color.BLACK);
*/
/* ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,new String[]{"hello","world","android","sun"});
Spinner sp = (Spinner)findViewById(R.id.Spinner01);
sp.setAdapter(aa);
*/
由于篇幅有限 这是半段代码 和下面的代码是一个完整的代码
老师讲的快,我也忘得快,所以请给我写出每段代码都是什么意思!我好复习,最好连开头的Actvity也讲了,java基础不牢 谢谢!下面是后段代码 谢谢了 !
/* ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked,new String[]{"hello","world","android","sun"});
ListView ls = (ListView)findViewById(R.id.ListView01);
ls.setAdapter(aa);
*/
final ProgressBar pb=(ProgressBar)findViewById(R.id.ProgressBar01);
pb.setMax(100);
pb.setProgress(50);
pb.setSecondaryProgress(70);
Button bnp = (Button)findViewById(R.id.Bup);
bnp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pb.incrementProgressBy(1);
pb.incrementSecondaryProgressBy(-1);
}
});
}}
代码里有注释是因为老师讲了几个功能,谢谢! 展开
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
public class Test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);
/*Button bn1 = (Button)findViewById(R.id.bn1);
Button bn2 = (Button)findViewById(R.id.bn2);
bn1.setText("");
bn2.setText("");
bn1.setBackgroundColor(Color.RED);
bn2.setBackgroundResource(R.drawable.exit1);
Resources re= getResources();
Drawable dr = re.getDrawable(R.drawable.icon);
bn1.setBackgroundDrawable(dr);
ImageView im = (ImageView)findViewById(R.id.ImageView01);
ImageButton imb = (ImageButton)findViewById(R.id.ImageButton01);
im.setImageResource(R.drawable.exit1);
imb.setImageDrawable(dr);
final Animation ani = AnimationUtils.loadAnimation(this, R.anim.anim);
bn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.startAnimation(ani);
}
});
RadioButton rb = (RadioButton)findViewById(R.id.RadioButton01);
rb.setBackgroundColor(Color.BLACK);
rb.setBackgroundResource(R.drawable.icon);
RadioGroup rg = (RadioGroup)findViewById(R.id.RadioGroup01);
rg.setBackgroundColor(Color.BLACK);
*/
/* ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,new String[]{"hello","world","android","sun"});
Spinner sp = (Spinner)findViewById(R.id.Spinner01);
sp.setAdapter(aa);
*/
由于篇幅有限 这是半段代码 和下面的代码是一个完整的代码
老师讲的快,我也忘得快,所以请给我写出每段代码都是什么意思!我好复习,最好连开头的Actvity也讲了,java基础不牢 谢谢!下面是后段代码 谢谢了 !
/* ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked,new String[]{"hello","world","android","sun"});
ListView ls = (ListView)findViewById(R.id.ListView01);
ls.setAdapter(aa);
*/
final ProgressBar pb=(ProgressBar)findViewById(R.id.ProgressBar01);
pb.setMax(100);
pb.setProgress(50);
pb.setSecondaryProgress(70);
Button bnp = (Button)findViewById(R.id.Bup);
bnp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pb.incrementProgressBy(1);
pb.incrementSecondaryProgressBy(-1);
}
});
}}
代码里有注释是因为老师讲了几个功能,谢谢! 展开
1个回答
展开全部
/*Button bn1 = (Button)findViewById(R.id.bn1);
Button bn2 = (Button)findViewById(R.id.bn2);
bn1.setText("");
bn2.setText("");
bn1.setBackgroundColor(Color.RED);
bn2.setBackgroundResource(R.drawable.exit1);
建立了两个button bn1和 R.id.bn1关联
bn2同
关联,简单点说就是 当有按下这个button,系统发出的消息中的标示是R.id.bn1
Resources re= getResources();
Drawable dr = re.getDrawable(R.drawable.icon);
bn1.setBackgroundDrawable(dr);
这段功能是获取 标记为R.drawable.icon的一张图片,并把bn1的背景设置为这张图片
ImageView im = (ImageView)findViewById(R.id.ImageView01);
ImageButton imb = (ImageButton)findViewById(R.id.ImageButton01);
im.setImageResource(R.drawable.exit1);
imb.setImageDrawable(dr);
读取一张图im,为R.drawable.exit1,
生成一个Imagebutton 关联为R.id.ImageButton01,同时这个button的图片是刚读取的图im.
final Animation ani = AnimationUtils.loadAnimation(this, R.anim.anim);
读取一个动画,标记为R.anim.anim(定义在某个xml文件内)
bn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.startAnimation(ani);
}
});
为bn2建立一个事件监听器,点击后 就显示刚才生成的动画
RadioButton rb = (RadioButton)findViewById(R.id.RadioButton01);
rb.setBackgroundColor(Color.BLACK);
rb.setBackgroundResource(R.drawable.icon);
RadioGroup rg = (RadioGroup)findViewById(R.id.RadioGroup01);
rg.setBackgroundColor(Color.BLACK);
也是生成一种button,具体lz看生成的界面就明白了,语法和刚才的代码差不多
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,new String[]{"hello","world","android","sun"});
Spinner sp = (Spinner)findViewById(R.id.Spinner01);
sp.setAdapter(aa);
建立一个字符串管理器,再建立一个Spinner对象叫sp,关联R.id.Spinner01
把刚才的配置器配给sp
这里spinner和adapter具体干什么的我身边没doc,不过你运行后的图形界面应该一眼就知道了,这里只是给你讲下语法
final ProgressBar pb=(ProgressBar)findViewById(R.id.ProgressBar01);
pb.setMax(100);
pb.setProgress(50);
pb.setSecondaryProgress(70);
Button bnp = (Button)findViewById(R.id.Bup);
bnp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pb.incrementProgressBy(1);
pb.incrementSecondaryProgressBy(-1);
}
});
}}
生成一个进度条和一个按钮,进度条有2条一个主条一个附条
按以下按钮主条+1附条-1
还有不会的hi我~
Button bn2 = (Button)findViewById(R.id.bn2);
bn1.setText("");
bn2.setText("");
bn1.setBackgroundColor(Color.RED);
bn2.setBackgroundResource(R.drawable.exit1);
建立了两个button bn1和 R.id.bn1关联
bn2同
关联,简单点说就是 当有按下这个button,系统发出的消息中的标示是R.id.bn1
Resources re= getResources();
Drawable dr = re.getDrawable(R.drawable.icon);
bn1.setBackgroundDrawable(dr);
这段功能是获取 标记为R.drawable.icon的一张图片,并把bn1的背景设置为这张图片
ImageView im = (ImageView)findViewById(R.id.ImageView01);
ImageButton imb = (ImageButton)findViewById(R.id.ImageButton01);
im.setImageResource(R.drawable.exit1);
imb.setImageDrawable(dr);
读取一张图im,为R.drawable.exit1,
生成一个Imagebutton 关联为R.id.ImageButton01,同时这个button的图片是刚读取的图im.
final Animation ani = AnimationUtils.loadAnimation(this, R.anim.anim);
读取一个动画,标记为R.anim.anim(定义在某个xml文件内)
bn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.startAnimation(ani);
}
});
为bn2建立一个事件监听器,点击后 就显示刚才生成的动画
RadioButton rb = (RadioButton)findViewById(R.id.RadioButton01);
rb.setBackgroundColor(Color.BLACK);
rb.setBackgroundResource(R.drawable.icon);
RadioGroup rg = (RadioGroup)findViewById(R.id.RadioGroup01);
rg.setBackgroundColor(Color.BLACK);
也是生成一种button,具体lz看生成的界面就明白了,语法和刚才的代码差不多
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,new String[]{"hello","world","android","sun"});
Spinner sp = (Spinner)findViewById(R.id.Spinner01);
sp.setAdapter(aa);
建立一个字符串管理器,再建立一个Spinner对象叫sp,关联R.id.Spinner01
把刚才的配置器配给sp
这里spinner和adapter具体干什么的我身边没doc,不过你运行后的图形界面应该一眼就知道了,这里只是给你讲下语法
final ProgressBar pb=(ProgressBar)findViewById(R.id.ProgressBar01);
pb.setMax(100);
pb.setProgress(50);
pb.setSecondaryProgress(70);
Button bnp = (Button)findViewById(R.id.Bup);
bnp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pb.incrementProgressBy(1);
pb.incrementSecondaryProgressBy(-1);
}
});
}}
生成一个进度条和一个按钮,进度条有2条一个主条一个附条
按以下按钮主条+1附条-1
还有不会的hi我~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询