Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide a field in landscape mode

Have any method to hide a field in landscape mode? Basically, I want:

android:visibility="GONE"

Just in landscape mode. Is possible? With a simple solution...

I tried this:

 public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
    {
        base.OnConfigurationChanged(newConfig);
        if(newConfig.Orientation == Android.Content.Res.Orientation.Landscape)
        {
// 1
        }
        else
        {
  // 2
        }

    } 

But does not work.

like image 434
GtOkAi Avatar asked Feb 14 '23 23:02

GtOkAi


2 Answers

Try something like:

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
  View my_view = findViewById(R.id.your_view);
  my_view.setVisibility(View.GONE);
}
like image 52
nKn Avatar answered Feb 24 '23 13:02

nKn


Ok I see you are using Xamarin with C#, try to be more specific with your questions, so we can help you =).

This is an example of how to hide and unhide a button?

// get the initial orientation
var surfaceOrientation = WindowManager.DefaultDisplay.Rotation;

if (surfaceOrientation == SurfaceOrientation.Rotation0 || surfaceOrientation == SurfaceOrientation.Rotation180) {
    button.Visibility=ViewStates.Invisible;  
 } else {
    button.Visibility=ViewStates.Visible;
 }

or

public override void OnConfigurationChanged (Android.Content.Res.Configuration newConfig)
  {
    base.OnConfigurationChanged (newConfig);                            
    if (newConfig.Orientation == Android.Content.Res.Orientation.Landscape) {
      button.Visibility=ViewStates.Invisible;        //invisible in landscape.
    } else if (newConfig.Orientation == Android.Content.Res.Orientation.Portrait) {
      button.Visibility=ViewStates.Visible;         //viible in portrait.
    }
like image 43
Jorgesys Avatar answered Feb 24 '23 15:02

Jorgesys