开发者

Screen resolution [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

Actually i have created an array of buttons,now my question is whether it will be fit in all screen resolution or not..as i have use nexus s device and the here its working fine..i mean to say that all the buttons are arranged in perfect order..more ever when i placed background image to each buttons its work fine..now i doubt whether it works for cheaper device by the same code i have written or i have to do something extra for that.thats means whether it fit for all screen resolution..or not..the code i have written is..

            LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout);
            LinearLayout rowLayout=null;

            LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,1);

            //Create Button
            for (i = 0; i<6; i++){
                rowLayout = new LinearLayout(this);
                rowLayout.setWeightSum(7);
                layoutVertical.addView(rowLayout,param);

                for(j=0;j<7;j++){
                    pBtnDay[i][j]=new Button(this);

                    rowLayout.addView(pBtnDay[i][j],param); 

                    pBtnDay[i][j].setOnLongClickListener(this);                         
                    pBtnDay[i][j].setOnClickListener(this);



                }
            }
            return true;

one more thing when i try to find wi开发者_Go百科dth and height of the buttons it return 0..why?


Using weightSum is the best solution if you know exactly how many elements you want displayed on your screen, across multiple devices. So if it shows up on, say a HTC Wildfire(LDPI) then it will also show on your Nexus(HDPI).

As for your second question, I´m assuming you are using View.getHeight() and View.getWidth() to obtain these values. Since your buttons hasn´t actually been drawn yet, Android has not designated dimension values to them, that´s why they turn up 0. If you need the width and height of these buttons in onCreate, then you need to do some math of your own :)


One of the basic philosophy in Adnroid Application is portability across platforms with different Screen Resolution, pixel depth and Oreintation.

How to achieve this, has been explained well in this link. Enjoy!

In case you are interested in getting Screen Parameters, then you can use DisplayMetrics and Window Manager. Shash


For the second answer: if you need the button dimension values, use:

@Override
  public void onWindowFocusChanged(boolean hasFocus) 
  {
      if (hasFocus)
      {
// calculates dimesions
      }
  }

In fact, as told before, in the onCreate you still have not calculate them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜