PostList

2016년 8월 23일 화요일

LinearLayout 크기변경





LinearLayout
 메소드
 -getWidth(), getHeight() 가로길이나 세로길이 가져오기
 -setLayoutParams , getLayoutParams

LayoutParams(가로길이, 세로길이) 혹은 (가로길이,세로길이,비중) 으로 이루어짐

layout.post run안에서 getWidth()나 getHeight()해야 값을 받아온다.

layout.post(new Runnable() {
            @Override
            public void run() {

            }
        });



 LinearLayout의 세로크기를 가로크기와 같게 바꾸기


코드는 다음과 같다.

final LinearLayout layout = (LinearLayout)findViewById(R.id.linear);

layout.post(new Runnable() {
@Override
public void run() {
Log.e(" I ", "Width size= " + layout.getWidth());
Log.e(" I ", "Height size= " + layout .getHeight());

LinearLayout.LayoutParams position = new LinearLayout.LayoutParams(layout.getWidth(),layout.getWidth()); 
//LayoutParams(가로크기,세로크기) 설정, 
layout.setLayoutParams(position); 
}
});
Log.e(" E ", "Width size= " + layout.getWidth());
Log.e(" E ", "Height size= " + layout .getHeight());


layout.post run에서 레이아웃의 크기를 가져와야 정상적으로 가져온다.




LinearLayout의 setLayoutParams을 이용하여  position LayoutParams을 적용시켰다.



댓글 1개: