first question here.
I am trying to develop an app using Xamarin and targetting android with C#. My problem starts when i instantize an instance of a TextView and try to manipulate it via code:
text = new TextView(context);
text.LayoutParameters = new GridView.LayoutParams(hwidth, hheight);
text.SetPadding(8, 8, 8, 8);
now i have been reading the android API and i need to change the gravity of this Textview so that the text is in the center but when i try:
text.setGravity(Gravity.CENTER);
It simply errors saying that Android.Widget.TextView does not contain a definition for 'setGravity'. Am i missing something ridiculously simple or what?
All help appreciated!
Though Java is basically used for Android game development, Android Studio has added Native Development Kit (NDK) to enable developers to use C++.
The Android Native Development Kit (NDK): a toolset that allows you to use C and C++ code with Android, and provides platform libraries that allow you to manage native activities and access physical device components, such as sensors and touch input.
C++ C++ can be used for Android App Development using the Android Native Development Kit(NDK). However, an app cannot be created totally using C++ and the NDK is used to implement parts of the app in C++ native code.
Bionic is an implementation of the standard C library, developed by Google for its Android operating system.
As @jarvis mentioned in the Comment
TextView.Gravity = GravityFlags.Center;
This will work.
You have to set LAYOUT gravity instead of gravity, you can try :
params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
xamarin allows you to use XML files ? If yes, you can set gravity into:
<TextView
android:id="@+id/smiley"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
Hope this help
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