728x90

www.androidpub.com/1620359

 

FrameLayout 에서 width, height 얻는 방법 좀..

        FrameLayout fl = (FrameLayout)findViewById(R.id.quiz_record);         int width = fl.getWidth();         int height = fl.getHeight(); 위에 이렇게 하면 둘다 0반환해요... 크기에 맞게 draw하고 싶은데.. 너비하고,

www.androidpub.com

stackoverflow.com/questions/21926644/get-height-and-width-of-a-layout-programmatically

 

Get height and width of a layout programmatically

I have designed an layout in which LinearLayout has 2 children LinearLayout and FrameLayout and in each child I put different views. I just wanted to measure height and width of FrameLayout so tha...

stackoverflow.com

FrameLayout 에서 width, height 얻는 방법을 찾아 봤다.

    //메모리에 올라갔을 때
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        Log.d(LOG, "MainActivity - onCreate() called")

        Log.d(LOG, " fragments_frame.height:${fragments_frame.height}")
        Log.d(LOG, " fragments_frame.width:${fragments_frame.width}")
        

처음에는 위에처럼 확인 했는데 사이즈가 0으로 나왔다.

위에 링크들 글들을 보면 FrameLayout이 그려지기 전에 확인해서 그렇다고 한다.

FrameLayout 사이즈 확인 하는 방법은 여러 가지가 있지만 가장 심플한 방법을 소개 하고자 한다.

    //메모리에 올라갔을 때
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        Log.d(LOG, "MainActivity - onCreate() called")

 		fragments_frame.post {
            Log.d(LOG, " fragments_frame.height:${fragments_frame.height}")
            Log.d(LOG, " fragments_frame.width:${fragments_frame.width}")
        }

 

위에 코드 처럼 

 fragments_frame.post {
            Log.d(LOG, " fragments_frame.height:${fragments_frame.height}")
            Log.d(LOG, " fragments_frame.width:${fragments_frame.width}")
        }

작성 해주면 onCreate 에서도 사이즈 확인이 가능 하다.

사이즈가 잘 나오는걸 확인 할 수 있다.

728x90

+ Recent posts