Cant increase font size of textview

Raihan Iqbal 121 Reputation points
2022-02-28T01:13:12.747+00:00

Hi,

I'm trying to increase the font size of a TextView element in a layout. When viewing the preview in Visual Studio code editor, it looks fine however when I run the application it's always the same small size.

Code editor preview:
178247-image.png

Actual:
178262-screenshot-20220228-120014.jpg

View code:

<?xml version="1.0" encoding="utf-8"?>  
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:orientation="vertical"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:layout_weight="1">  
    <TextureView  
        android:id="@+id/cameraView"  
        android:layout_marginTop="-95dp"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content" />  
    <TextView  
        android:layout_width="fill_parent"  
        android:layout_height="70dp"  
        android:textAlignment="center"  
        android:id="@+id/txtDeviceCount"  
        android:text="Trackers Found: 0"  
        android:textSize="50dp"  
        android:textColor="#ffffff" android:background="#000" />  
    <ImageView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:scaleType="fitXY"  
        android:layout_gravity="center_vertical"  
        android:layout_marginHorizontal="80dp"  
        android:id="@+id/imgScannerBox"  
        android:background="@drawable/scannerbox"  
        android:layout_weight="0"  
        android:maxWidth="200dp"  
        android:minWidth="200dp"  
        android:maxHeight="200dp"  
        android:minHeight="200dp" />  
    <Button  
        android:id="@+id/takePhotoButton"  
        android:layout_width="65dp"  
        android:layout_height="65dp"  
        android:layout_marginBottom="15dp"  
        android:layout_gravity="center|bottom"  
        android:background="@drawable/scan_stop_button" />  
</FrameLayout>  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,305 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Raihan Iqbal 121 Reputation points
    2022-03-01T02:57:27.897+00:00

    Instead of using a layout file, I created a custom renderer and wrote my UI code in there.

    public class CameraPageRenderer : PageRenderer
    {
        .....
    
        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
                base.OnElementChanged(e);
                SetupUserInterface();
         }
    
         void SetupUserInterface()
            {
                mainLayout = new RelativeLayout(Context);
                liveView = new TextureView(Context);
    
                RelativeLayout.LayoutParams liveViewParams = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MatchParent,
                    RelativeLayout.LayoutParams.MatchParent);
                liveView.LayoutParameters = liveViewParams;
                liveView.SurfaceTextureListener = this;
                mainLayout.AddView(liveView);
    
                txtDeviceCount = new TextView(Context);
                txtDeviceCount.TextSize = 20;
                txtDeviceCount.Text = "Trackers Found: 0";
                txtDeviceCount.SetTextColor(Android.Graphics.Color.White);
                RelativeLayout.LayoutParams txtDeviceCountParams = new RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
                txtDeviceCount.TextAlignment = Android.Views.TextAlignment.Center;
                txtDeviceCount.LayoutParameters = txtDeviceCountParams;
                mainLayout.AddView(txtDeviceCount);
    
                AddView(mainLayout);
         }
    }