即使我使用正确的尺寸(hdpi,mdpi,xxhdpi ...),选项卡上的图像图标也会显得非常小 [英] Image icon on tabs appear very small even though I'm using the correct dimensions (hdpi, mdpi, xxhdpi ...)

查看:146
本文介绍了即使我使用正确的尺寸(hdpi,mdpi,xxhdpi ...),选项卡上的图像图标也会显得非常小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照Google开发者页面上的指南来创建这5个文件夹,并用正确尺寸的图标填充它们:

I followed the guidelines on the Google developer page to creat these 5 folders and filled them with icons of the correct dimensions:

我使用 TabHost 创建了我的标签,如下所示:

I created my tabs using a TabHost like so:

TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();

    TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1");
    spec1.setContent(R.id.tab1);
    spec1.setIndicator("", getResources().getDrawable(R.drawable.homeicon));
    TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
    spec2.setContent(R.id.tab2);
    spec2.setIndicator("", getResources().getDrawable(R.drawable.startachainwhite48dp));
    TabHost.TabSpec spec3 = tabHost.newTabSpec("tab3");
    spec3.setContent(R.id.tab3);
    spec3.setIndicator("", getResources().getDrawable(R.drawable.joinachainwhite48dp));
    TabHost.TabSpec spec4 = tabHost.newTabSpec("tab4");
    spec4.setContent(R.id.tab4);
    spec4.setIndicator("", getResources().getDrawable(R.drawable.viewchainswhite48dp));
    TabHost.TabSpec spec5 = tabHost.newTabSpec("tab5");
    spec5.setContent(R.id.tab5);
    spec5.setIndicator("", getResources().getDrawable(R.drawable.profilewhite48dp));

    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.addTab(spec3);
    tabHost.addTab(spec4);
    tabHost.addTab(spec5);

但由于某些原因,我的标签上的图标(在底部)显示很小

But for some reason the icons on my tabs (at the bottom) show up tiny

有人对此有解释/解决方案吗?我觉得我在某个地方犯了一个愚蠢的错误 - 如果需要,会发布xml布局。提前致谢。

Does anybody have an explanation/solution for this? I feel like I have made a silly mistake somewhere - will post xml layout if needed. Thanks in advance.

编辑:可能值得一提的是我在上面的代码中使用的getDrawable()方法已被弃用(API 22)

It may be worth mentioning that the getDrawable() method I'm using in the above code is deprecated (API 22)

EDIT2:完整XML布局

Full XML layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tool_bar_test"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#FF86B39A"
    android:fitsSystemWindows="true"
    android:gravity="top"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:text="Test"
            android:textColor="#ffffff"
            android:textSize="25sp"
            android:textStyle="bold" />
    </LinearLayout>
</android.support.v7.widget.Toolbar>

<android.support.v4.widget.DrawerLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.sv_laptop03.myapp.Profile">

        <TabHost
            android:id="@+id/tabHost"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"></TabWidget>

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <RelativeLayout
                        android:id="@+id/tab1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"></RelativeLayout>

                    <RelativeLayout
                        android:id="@+id/tab2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                    </RelativeLayout>

                    <RelativeLayout
                        android:id="@+id/tab3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"></RelativeLayout>

                    <RelativeLayout
                        android:id="@+id/tab4"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"></RelativeLayout>

                    <RelativeLayout
                        android:id="@+id/tab5"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"></RelativeLayout>
                </FrameLayout>
            </RelativeLayout>
        </TabHost>
    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/headerview"
        app:menu="@menu/drawer" />

</android.support.v4.widget.DrawerLayout>

推荐答案

要确保每件事物都符合您的预期,只需将图像添加到 xxxhdpi 文件夹中,并确保它们是192x192像素。

To make sure that every thing will looks as you expected, just add images into the xxxhdpi folder and be sure that they are 192x192 px.

通过这种方法,您可以让OpenGL将图像转换为运行该应用程序的设备,并且还可以让您在不丢失任何细节的情况下调整图像大小。

By this method you let the OpenGL convert the image to what device the app is running on and that also give you the ability to resize your images without losing any details.

希望这会对你有帮助。

参考这里:
https://developer.android.com/guide/practices/screens_support.html

Hope this will help you.
Reference here: https://developer.android.com/guide/practices/screens_support.html

这篇关于即使我使用正确的尺寸(hdpi,mdpi,xxhdpi ...),选项卡上的图像图标也会显得非常小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆