大佬教程收集整理的这篇文章主要介绍了android – 使用单个按钮宽度以编程方式填充父级,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public class test_GIFDisplay extends Activity implements View.onClickListener { SurfaceView sview; GifRun gr = new GifRun(); Button btnBACk; protected void onCreate(Bundle savedInstanceStatE) { super.onCreate(savedInstanceStatE); sview = new SurfaceView(this); sview.setZOrderOnTop(true); gr.LoadGiff(sview,this,R.drawable.smiley); LinearLayout linearLayout1 = new LinearLayout(this); linearLayout1.setOrientation(LinearLayout.VERTICAL); linearLayout1.setBACkgroundColor(Color.parseColor("#27ae60")); linearLayout1.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT)); LinearLayout linearLayout2 = new LinearLayout(this); linearLayout2.setOrientation(LinearLayout.VERTICAL); linearLayout2.setBACkgroundColor(Color.parseColor("#27ae60")); linearLayout2.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT)); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); p.weight = 1.0f; btnBACk = new Button (this); btnBACk.setText("BACk"); btnBACk.setBACkgroundColor(Color.parseColor("#f1c40f")); btnBACk.setGravity(Gravity.CENTER_HORIZONTAL); btnBACk.setLayoutParams(p); btnBACk.setOnClickListener(this); linearLayout2.addView(btnBACk); linearLayout1.addView(linearLayout2); linearLayout1.addView(sview); setContentView(linearLayout1); } @Override public void onClick(View view) { btnBACk = (Button) view; btnBACk.setBACkgroundColor(Color.parseColor("#2980b9")); //color change new CountDownTimer(100,50) { @Override public void onTick(long arg0) { // TODO Auto-generated method stub } @Override public void onFinish() { btnBACk.setBACkgroundColor(Color.parseColor("#f1c40f")); // original color } }.start();//end color changed finish(); } }@H_772_2@
linearLayout2.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
我希望这有帮助.
P.S:你可以为按下和选择的状态创建按钮的选择器,而不是使用计时器来显示按下的按钮效果.这是一个基本链接,可以帮助您实现这一目标:android button selector
@H_772_2@ @H_772_2@以上是大佬教程为你收集整理的android – 使用单个按钮宽度以编程方式填充父级全部内容,希望文章能够帮你解决android – 使用单个按钮宽度以编程方式填充父级所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。