immp8q
Last Updated: January 28, 2019
·
19.36K
· ignaciogs

Get height of a view in onCreate method (Android)

final LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
final ViewTreeObserver observer= layout.getViewTreeObserver();
observer.addOnGlobalLayoutListener(
    new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
            public void onGlobalLayout() {
                Log.d("Log", "Height: " + layout.getHeight());
            }
        });

5 Responses
Add your response

30108

package com.animation;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.LinearLayout;

public class AnimateScreen extends Activity {

//Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout ll = new LinearLayout(this);

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAPCONTENT, LinearLayout.LayoutParams.WRAPCONTENT);
layoutParams.setMargins(30, 20, 30, 0);

Button bt = new Button(this);
bt.setText(String.valueOf(bt.getWidth()));

RotateAnimation ra = new RotateAnimation(0,360,bt.getWidth() / 2,bt.getHeight() / 2);
ra.setDuration(3000L);
ra.setRepeatMode(Animation.RESTART);
ra.setRepeatCount(Animation.INFINITE);
ra.setInterpolator(new LinearInterpolator());

bt.startAnimation(ra);

ll.addView(bt,layoutParams);

setContentView(ll);

best regards

https://youtubego.me/ https://black-mart.net/

7 months ago ·
30169

thank you for sharing <a href="http://freemoneytransferapps.xyz/">free money transfer apps</a>

7 months ago ·
30457

Just download the latest PES 2019 APK and OBB files from here http://pes2019download.com/

6 months ago ·
30561
30973

I'm looking for a good way to measure the dimensions of the actual content area for an activity in Android.
https://www.playbuzz.com/voippe10

4 months ago ·