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.
Try something like:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
View my_view = findViewById(R.id.your_view);
my_view.setVisibility(View.GONE);
}
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.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With