Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.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
Java 即使I';m使用正确的尺寸(hdpi、mdpi、xxhdpi…)_Java_Android_Tabs - Fatal编程技术网

Java 即使I';m使用正确的尺寸(hdpi、mdpi、xxhdpi…)

Java 即使I';m使用正确的尺寸(hdpi、mdpi、xxhdpi…),java,android,tabs,Java,Android,Tabs,我按照Google开发者页面上的指导原则创建了这5个文件夹,并用正确尺寸的图标填充它们: 我使用TabHost创建了我的选项卡,如下所示: TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1"); spec1.setContent(R.id.tab1); spec1.se

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

我使用
TabHost
创建了我的选项卡,如下所示:

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);
但由于某些原因,我标签上的图标(在底部)显示得很小

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

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

EDIT2:完整XML布局

<?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像素

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

希望这对您有所帮助。
此处参考:

是的,我已经使用该链接完成了。这是meremove从其他文件夹中删除除xxxhdpi以外的所有其他资源的结果:)然后尝试设置特定的最小宽度和最小高度:)我认为这样做的全部意义在于,您的图标会自动缩放到适当的大小,而不必自己缩放它们,但如果您不进行某些限制,您会这样做结果和以前一样。。这里的主要想法是让你的应用程序尽可能轻。显示你的XML,因为我怀疑罪魁祸首潜伏在那里。至于不推荐的方法,你应该使用
ContextCompat.getDrawable(context,R.drawable.**)
而不是发布XML布局,谢谢。你好@eyensberg你解决了这个问题吗。。?