Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中调整Xamarin表单中的选项卡栏图标大小_Android_Xamarin - Fatal编程技术网

在Android中调整Xamarin表单中的选项卡栏图标大小

在Android中调整Xamarin表单中的选项卡栏图标大小,android,xamarin,Android,Xamarin,大家好,我正在从事一个xamarin项目,我正在向我的选项卡栏添加图标,但图像如下所示 我这样做是为了在IOS上工作,但安卓给我带来了困难。就像昨天一样,我刚刚了解到它不仅仅是制作一个自定义渲染器,而且我还必须深入到布局文件夹并创建一个自定义axml文件 无论如何,我在堆栈溢出上遵循了这个非常有用的示例,我能够调整文本大小,但图像没有调整大小。本质上,我想使标签中的文本变小,图标变大。这是在IOS上完成的,但正如我提到的,我在安卓上苦苦挣扎。 以下是我到目前为止的情况。我想我实现它可能是错误的,

大家好,我正在从事一个xamarin项目,我正在向我的选项卡栏添加图标,但图像如下所示

我这样做是为了在IOS上工作,但安卓给我带来了困难。就像昨天一样,我刚刚了解到它不仅仅是制作一个自定义渲染器,而且我还必须深入到布局文件夹并创建一个自定义axml文件

无论如何,我在堆栈溢出上遵循了这个非常有用的示例,我能够调整文本大小,但图像没有调整大小。本质上,我想使标签中的文本变小,图标变大。这是在IOS上完成的,但正如我提到的,我在安卓上苦苦挣扎。 以下是我到目前为止的情况。我想我实现它可能是错误的,因为上面提到的一些术语被弃用了,所以我不得不用新方法实现它

公共类TabbedPageRenderAndriod:TabbedPageRenderer
{
公共选项卡PageRenderAndriod(上下文):基(上下文)
{
}
受保护的覆盖无效SetTabIconImageSource(TabLayout.Tab,可绘制图标)
{
base.SetTabIconImageSource(选项卡,图标);
tab.SetCustomView(Resource.Layout.CustomTab);
var imageView=tab.CustomView.findviewbyd(Resource.Id.icon);
imageView.SetBackground(选项卡图标);
}   
}
我的布局->CustomTab.axml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
  <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:scaleType="fitCenter"
        android:id="@+id/icon"
        android:layout_gravity="center_horizontal" />
</LinearLayout>


我现在理解了这个过程,但我不确定我是否正确地做到了这一点。我还想指出左边的图标是我想放大的。我还尝试添加一个较大的图像以查看是否需要时间,但它们都默认为图像中显示的大小这可能有点晚了,但我遇到了相同的问题。 我通过创建自定义渲染器解决了此问题:

[assembly: ExportRenderer(typeof(TabbedPage), typeof(CustomTabbedPageRenderer))]
namespace TabBarIconSize.Droid
{   
    class CustomTabbedPageRenderer : TabbedPageRenderer
    {
        public CustomTabbedPageRenderer(Context context)
            : base(context)
        {

        }

        protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
        {
            base.OnElementChanged(e);

            // Get TabbedPage's bottomNavigationView
            var bottomNavigationView = (GetChildAt(0) as Android.Widget.RelativeLayout).GetChildAt(1) as BottomNavigationView;
            
            // Set Icon size
            bottomNavigationView.ItemIconSize = 50;
        }
}
[程序集:ExportRenderer(typeof(TabbedPage)、typeof(CustomTabbedPageRenderer))]
名称空间tabbaricosize.Droid
{   
类CustomTabbedPageRenderer:TabbedPageRenderer
{
公共CustomTabbedPageRenderer(上下文)
:基本(上下文)
{
}
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
//获取选项卡页的底部导航视图
var bottomNavigationView=(GetChildAt(0)作为Android.Widget.RelativeLayout)。GetChildAt(1)作为bottomNavigationView;
//设置图标大小
bottomNavigationView.ItemIconSize=50;
}
}

这可能有点晚了,但我遇到了同样的问题。 我通过创建自定义渲染器解决了此问题:

[assembly: ExportRenderer(typeof(TabbedPage), typeof(CustomTabbedPageRenderer))]
namespace TabBarIconSize.Droid
{   
    class CustomTabbedPageRenderer : TabbedPageRenderer
    {
        public CustomTabbedPageRenderer(Context context)
            : base(context)
        {

        }

        protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
        {
            base.OnElementChanged(e);

            // Get TabbedPage's bottomNavigationView
            var bottomNavigationView = (GetChildAt(0) as Android.Widget.RelativeLayout).GetChildAt(1) as BottomNavigationView;
            
            // Set Icon size
            bottomNavigationView.ItemIconSize = 50;
        }
}
[程序集:ExportRenderer(typeof(TabbedPage)、typeof(CustomTabbedPageRenderer))]
名称空间tabbaricosize.Droid
{   
类CustomTabbedPageRenderer:TabbedPageRenderer
{
公共CustomTabbedPageRenderer(上下文)
:基本(上下文)
{
}
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
//获取选项卡页的底部导航视图
var bottomNavigationView=(GetChildAt(0)作为Android.Widget.RelativeLayout)。GetChildAt(1)作为bottomNavigationView;
//设置图标大小
bottomNavigationView.ItemIconSize=50;
}
}

你的图像大小是多少?它与更多的图像相同吗?更多的图像看起来不错。是的,我希望它们更大,我可以通过添加更大的尺寸来更改IOS上的图标大小,但在android上,我添加了不同的尺寸,看起来是一样的。我已经开始查看自定义渲染器,但运气不好,是的,图像大小是y你可以这样做。你的图像大小是多少?它与更多的图像相同吗?更多的图像看起来不错。是的,我希望它们更大,我可以通过添加更大的尺寸来更改IOS上的图标大小,但在安卓上,我添加了不同的尺寸,看起来是一样的。我已经开始查看自定义渲染器,但没有运气是的,有图像你可以按照尺寸来做。对我来说很好谢谢!对我来说很好谢谢!