<pre name="code" class="java"> public void setFooterHeightWithScreen() { //得到屏幕分辨率 int srcWidth =getWindowManager().getDefaultDisplay().getWidth(); // Log.i("f", srcWidth.toString()); //System.out.print(srcWidth); //得到按钮 Button b1 = (Button) findViewById(R.id.footer1); Button b2 = (Button) findViewById(R.id.footer2); Button b3 = (Button) findViewById(R.id.footer3); Button b4 = (Button) findViewById(R.id.footer4); //得到按钮图片的高 Drawable r=this.getResources().getDrawable(R.drawable.main_hunt0); BitmapDrawable b=(BitmapDrawable)r; Bitmap t=b.getBitmap(); t.getHeight(); //通过按钮得到父控件 根据屏幕分辨率设置高 LinearLayout.LayoutParams l=(LayoutParams) b1.getLayoutParams(); int i=(int)((srcWidth/4.0* t.getHeight())/(t.getWidth())); l.height=i; b1.setLayoutParams(l); b2.setLayoutParams(l); b3.setLayoutParams(l); b4.setLayoutParams(l); // int i=(int)((srcWidth/4.0* b1.getHeight())/(b1.getWidth())); // b1.setHeight(i); }
未经允许,不得转载。
时间: 2024-10-08 06:30:46