1

您好正在为所有尺寸做一个应用程序。在这里,如果在 xml 文件中获取 imageview,我将使用显示指标显示 imageview,我的代码适用于所有尺寸,但是如果我在那个时候动态地获取 imageview,同时给出边距,我会遇到异常,任何人都可以帮助我....

my code:

         ImageView I2=(ImageView)findViewById(R.id.caption);
                     captionbitmap=BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.practise));

          captiondrwable = new BitmapDrawable(captionbitmap); 
             I2.setBackgroundDrawable(captiondrwable);
   RelativeLayout.LayoutParams layoutcap= (RelativeLayout.LayoutParams) I2.getLayoutParams();      
             layoutcap.height=(int)(50*(screenHeight/600));  
             layoutcap.width=(int)(80*(screenWidth/1024));
             layoutcap.topMargin=(int)(50*(screenHeight/600)); 
             layoutcap.leftMargin=(int)(15*(screenWidth/1024));
       // above   code working well for all sizes



            ImageView I2=new ImageView(this);

          captionbitmap=BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.practise));

          captiondrwable = new BitmapDrawable(captionbitmap); 
             I2.setBackgroundDrawable(captiondrwable);
   RelativeLayout.LayoutParams layoutcap= (RelativeLayout.LayoutParams) I2.getLayoutParams();      
             layoutcap.height=(int)(50*(screenHeight/600));  
             layoutcap.width=(int)(80*(screenWidth/1024));
             layoutcap.topMargin=(int)(50*(screenHeight/600)); 
             layoutcap.leftMargin=(int)(15*(screenWidth/1024));


    // above imageview i gave dynamically that my code is not working so pls any one give me any        idea
4

0 回答 0