question

njsokalski avatar image
0 Votes"
njsokalski asked ·

Refreshing Height & Width of a View in Xamarin.Android

I have an Extension Method that displays a View (a TextView to be specific). The View usually has a Visibility of Gone before the method is called, so the first thing I do in the method is set Visibility to Visible. However, the Width & Height properties are still 0 at this point. The next time I call the method, the Width & Height are updated, however, I need to update them immediately after setting Visibility to Visible so that I can use them in the Extension Method. How do I do this? (NOTE: I will mention, in case it makes any difference, that android:layout_width is set to a literal value in the xml, but android:layout_height is just the usual wrap_content) Thanks.

dotnet-android
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The View usually has a Visibility of Gone before the method is called, so the first thing I do in the method is set Visibility to Visible.

Hi, njsokalski. How did you display the textView? Could you post the related code? I created a basic demo to test the function, it works fine. Here is the related code:

<TextView
    android:text="Text"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:id="@+id/textView1" />
<Button
    android:text="Button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button1" />

Button's click event:

FindViewById<Button>(Resource.Id.button1).Click += {
    var textView = FindViewById<TextView>(Resource.Id.textView1);
    textView.Visibility = Android.Views.ViewStates.Visible;
}
0 Votes 0 ·

0 Answers