2014-02-14 5 views

ответ

3
//ImageView Setup 
ImageView imageView = new ImageView(this); 

//setting height and width of imageview 
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

//setting margins around imageimageview 
params.setMargins(10, 10, 10, 10); //left, top, right, bottom 

//adding attributes to the imageview 
imageView.setLayoutParams(params); 
3

Это может быть достигнуто с помощью как программно, так и через XML

1) С помощью программно может быть trickest один.

You can get the width and height of the screen and set one parameter for both 
layout_width and layout_height of button. 

Как ??

Display display=((WindowManager)getSystemService(Context.WINDOW_SERVICE)). 
             getDefaultDisplay(); 
    int width=display.getWidth(); 
    int height=display.getHeight(); 

// Вычислить ширина и высота

Say For screen 240*320 

buttonWidth=width/5;  result: buttonWidht=48; 
buttonHeight=height/10 result: buttonHeight=32; 

Использование LayoutParams объекта, установить ширину и высоту кнопки.

Теперь, если вы запустите этот код на устройство с размером экрана 320 * 480

buttonWidth=width/5;  result: buttonWidht=64; 
buttonHeight=height/10 result: buttonHeight=48; 

и так далее для других устройств тоже.

2) Через Xml вы можете добиться этого, что будет легче реализовать

You just need to put your xml file in different folders of res and change the 
values of your views accordingly. 

Example: if you have main.xml 

res>layout>main.xml. 
res>layout-small>main.xml 
res>layout-large>main.xml 
res>layout-xlarge>main.xml 

now you just need to change the values of your button's width and height. 
in each main.xml 
5

Привет друг вы можете установить на этом ниже код

btnPlayVideo.getLayoutParams().height = XX; 
btnPlayVideo.getLayoutParams().width = XX; 

или посмотреть imageButton resize

Смежные вопросы