FANDOM



In an Activity, specify which View is to control the layout;Edit

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set the content view to be what is defined in the res/layout/main.xml file
setContentView(R.layout.main);

..

}

find a View and cast it to the correct type;Edit

returnedImageView = (ImageView) findViewById(R.id.ReturnedImageView);

show a view;Edit

someView.setVisibility(View.VISIBLE);

hide a ViewEdit

someView.setVisibility(View.GONE);


get the height and width of a View in the view itselfEdit

getHeight and getWidth will return 0 if called from onCreate, use this method as a work-around


protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

View view = findViewById(R.id.main_my_view);

view.post(new Runnable() {
//Get size of view after layout

@Override
public void run() {

   Log.d(TAG, 
      "view has width: "+view.getWidth() + 
      " and height: "+view.getHeight());

     }
   });
}





ef