Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.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 为平板电脑和手机android创建布局_Java_Android_Android Layout_Layout_Hdpi - Fatal编程技术网

Java 为平板电脑和手机android创建布局

Java 为平板电脑和手机android创建布局,java,android,android-layout,layout,hdpi,Java,Android,Android Layout,Layout,Hdpi,好的,我读了很多关于为android设备创建布局的书。当我不在的时候,我以为我在正确的道路上。我的情况是: 我创建了布局正常,布局正常的土地,布局小,布局小土地等。。。然后,我得到值normal ldpi、值normal mdpi和所有其他限定符。我把尺寸放在那些文件夹中,在我的布局中,我只使用它们。这是我的布局代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http:/

好的,我读了很多关于为android设备创建布局的书。当我不在的时候,我以为我在正确的道路上。我的情况是:

我创建了布局正常,布局正常的土地,布局小,布局小土地等。。。然后,我得到值normal ldpi、值normal mdpi和所有其他限定符。我把尺寸放在那些文件夹中,在我的布局中,我只使用它们。这是我的布局代码:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#e8e8e8"
    android:orientation="vertical">


    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbarMainScreen"
        android:layout_width="match_parent"
        android:layout_height="@dimen/visinaHeadera"
        android:background="#1d6cb5"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/Widget.AppCompat.Toolbar">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:background="@drawable/senkaokoikonica"
            android:scaleType="center"
            android:src="@drawable/homeicon" />

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

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="@dimen/razmakOdHomeDoTexta"
                android:layout_weight="1"
                android:paddingTop="@dimen/marginaTextaZaIspisuHeaderu"
                android:text="Akcije i katalozi"
                android:textAlignment="center"
                android:textColor="#ffffff"
                android:textSize="15sp"
                android:typeface="sans" />


            <ImageButton
                android:id="@+id/imageButtonOtvoriSearch"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/search_klik"
                android:scaleType="center"
                android:src="@drawable/searchicon" />

            <View
                android:layout_width="@dimen/razmakIzmedjuLupeIShare"
                android:layout_height="match_parent" />

            <ImageButton
                android:id="@+id/shareButtonKataloziMainScreen"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/senkaokoikonica"
                android:scaleType="center"
                android:src="@drawable/shareicon" />

            <View
                android:layout_width="@dimen/razmakIzmedjuLupeIShare"
                android:layout_height="match_parent" />

            <ImageButton
                android:id="@+id/settingsButtonMainScreen"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@drawable/senkaokoikonica"
                android:scaleType="center"
                android:src="@drawable/settingsicon" />

            <View
                android:layout_width="@dimen/razmakIzmedjuSettingsIDesnogKraja"
                android:layout_height="match_parent" />


        </LinearLayout>


    </android.support.v7.widget.Toolbar>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="3.33dp"
        android:layout_below="@+id/toolbarMainScreen"
        android:background="@drawable/headshad480" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="3.33dp"
        android:layout_below="@+id/linearLayoutZaSearchMainScreen"
        android:background="@drawable/headshad480"
        android:visibility="invisible" />


    <LinearLayout
        android:id="@+id/linearLayoutZaSearchMainScreen"
        android:layout_width="match_parent"
        android:layout_height="@dimen/visinaDrugogHeadera"
        android:layout_below="@+id/toolbarMainScreen"
        android:background="@drawable/searchbg"
        android:orientation="horizontal"
        android:visibility="invisible">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/searchbg">

            <EditText
                android:id="@+id/editTextMainScreen"
                android:layout_width="match_parent"
                android:layout_height="@dimen/editTextSearchVisina"
                android:layout_marginBottom="@dimen/editTextMarginaBot"
                android:layout_marginLeft="@dimen/editTextMarginaLeft"
                android:layout_marginRight="@dimen/editTextMarginaRight"
                android:layout_marginTop="@dimen/editTextMarginaTop"
                android:layout_weight="1"
                android:background="@drawable/edittext_conrer"
                android:hint="Pretraga"
                android:textColor="#000000"
                android:textColorHint="#000000"
                android:textStyle="italic" />
        </LinearLayout>


        <ImageButton
            android:id="@+id/imageButtonSearch"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/searchButtSearchVisina"
            android:layout_gravity="right"
            android:layout_marginBottom="@dimen/searchButtMarginaBot"
            android:layout_marginRight="@dimen/searchButtMarginaRight"
            android:layout_marginTop="@dimen/searchButtMarginaTop"
            android:background="@drawable/search_klik"
            android:scaleType="center"
            android:src="@drawable/searchiconkrug" />

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_above="@+id/linearLayoutZaReklameMainScreen"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/toolbarMainScreen"
        android:layout_weight="1"
        android:baselineAligned="false"
        android:orientation="vertical">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical">


                <ImageButton
                    android:id="@+id/buttonProdavci"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_marginBottom="@dimen/marginIzmedjuSlika"
                    android:layout_marginLeft="@dimen/marginIzmedjuSlikaIZida"
                    android:layout_marginRight="@dimen/marginIzmedjuSlika"
                    android:layout_marginTop="@dimen/marginTopZaGornjeSlike"
                    android:layout_weight="1"
                    android:background="@drawable/prodavci"
                    android:scaleType="center" />


            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical">


                <ImageButton
                    android:id="@+id/buttonProizvodi"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_marginBottom="@dimen/marginIzmedjuSlika"
                    android:layout_marginLeft="@dimen/marginIzmedjuSlika"
                    android:layout_marginRight="@dimen/marginIzmedjuSlikaIZida"
                    android:layout_marginTop="@dimen/marginTopZaGornjeSlike"
                    android:layout_weight="1"
                    android:background="@drawable/proizvodi"
                    android:scaleType="center" />


            </LinearLayout>


        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical">

                <ImageButton
                    android:id="@+id/buttonBarkod"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_marginBottom="@dimen/marginIzmedjuSlikaIZida"
                    android:layout_marginLeft="@dimen/marginIzmedjuSlikaIZida"
                    android:layout_marginRight="@dimen/marginIzmedjuSlika"
                    android:layout_marginTop="@dimen/marginIzmedjuSlika"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:background="@drawable/barcode"
                    android:scaleType="center" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical">


                <ImageButton
                    android:id="@+id/buttonSviKatalozi"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_centerHorizontal="true"
                    android:layout_marginBottom="@dimen/marginIzmedjuSlikaIZida"
                    android:layout_marginLeft="@dimen/marginIzmedjuSlika"
                    android:layout_marginRight="@dimen/marginIzmedjuSlikaIZida"
                    android:layout_marginTop="@dimen/marginIzmedjuSlika"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:background="@drawable/svikatalozi"
                    android:scaleType="center" />


            </LinearLayout>


        </LinearLayout>


    </LinearLayout>


    <LinearLayout
        android:id="@+id/linearLayoutZaReklameMainScreen"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center|bottom">

        <com.google.android.gms.ads.AdView
            android:id="@+id/adViewMainScreen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_gravity="bottom|center"
            ads:adSize="BANNER"
            ads:adUnitId="@string/aik_ad_unit_id"></com.google.android.gms.ads.AdView>


    </LinearLayout>


    <LinearLayout
        android:id="@+id/lejoutZaTransparentonstMainScreen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_below="@id/toolbarMainScreen"
        android:alpha=".35"
        android:background="#000000"
        android:orientation="horizontal"
        android:visibility="invisible" />


</RelativeLayout>

不过,当我在我的设备(三星Galaxy s2 plus)上测试它时,它看起来非常好。当我在Nexus5上测试它时,它看起来甚至都不接近


关于如何为手机和平板电脑的最佳解决方案创建足够数量的布局有何建议?

您可以使用这些布局来支持所有屏幕尺寸:

布局#适用于手机(小于600dp的可用宽度)

布局-sw600dp#适用于7英寸平板电脑(600dp宽和更大)

布局-sw720dp#适用于10英寸平板电脑(720dp宽和更大)


您可以使用这些布局来支持所有屏幕尺寸:

布局#适用于手机(小于600dp的可用宽度)

布局-sw600dp#适用于7英寸平板电脑(600dp宽和更大)

布局-sw720dp#适用于10英寸平板电脑(720dp宽和更大)


您可以使用这些布局来支持所有屏幕尺寸:

布局#适用于手机(小于600dp的可用宽度)

布局-sw600dp#适用于7英寸平板电脑(600dp宽和更大)

布局-sw720dp#适用于10英寸平板电脑(720dp宽和更大)


您可以使用这些布局来支持所有屏幕尺寸:

布局#适用于手机(小于600dp的可用宽度)

布局-sw600dp#适用于7英寸平板电脑(600dp宽和更大)

布局-sw720dp#适用于10英寸平板电脑(720dp宽和更大)



还有一个问题。我应该将每个密度的维度存储在values文件夹中,还是?是的,您可以这样做,因为为不同密度定义维度的值将为您的代码提供灵活性。它还将提供可重用性。是的,但是,如果我从这个比率存储mdpi=1,hdpi=1.5,等等,手机的分辨率不重要吗?你可以这样做布局-sw600dp如何创建景观?还有一个问题。我应该将每个密度的维度存储在values文件夹中,还是?是的,您可以这样做,因为为不同密度定义维度的值将为您的代码提供灵活性。它还将提供可重用性。是的,但是,如果我从这个比率存储mdpi=1,hdpi=1.5,等等,手机的分辨率不重要吗?你可以这样做布局-sw600dp如何创建景观?还有一个问题。我应该将每个密度的维度存储在values文件夹中,还是?是的,您可以这样做,因为为不同密度定义维度的值将为您的代码提供灵活性。它还将提供可重用性。是的,但是,如果我从这个比率存储mdpi=1,hdpi=1.5,等等,手机的分辨率不重要吗?你可以这样做布局-sw600dp如何创建景观?还有一个问题。我应该将每个密度的维度存储在values文件夹中,还是?是的,您可以这样做,因为为不同密度定义维度的值将为您的代码提供灵活性。它还将提供可重用性。是的,但是,如果我从这个比率存储mdpi=1,hdpi=1.5,等等,手机的分辨率不重要吗?你可以这样做布局-sw600dp如何创建景观?