Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.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-如何为多个屏幕设置单一布局_Android_Android Layout - Fatal编程技术网

Android-如何为多个屏幕设置单一布局

Android-如何为多个屏幕设置单一布局,android,android-layout,Android,Android Layout,我是初学者。我正在开发一个应用程序,其中我面临一个奇怪的布局问题。 当我在小型设备上运行我的应用程序时,它工作正常,但当我在大屏幕设备上运行它时,它的布局属性会自动改变。 请让我知道是否有任何方法,我可以创建一个单一的布局编程为所有屏幕大小? 我的xml是 <RelativeLayout android:id="@+id/contents" android:layout_width="match_parent" android:layout

我是初学者。我正在开发一个应用程序,其中我面临一个奇怪的布局问题。 当我在小型设备上运行我的应用程序时,它工作正常,但当我在大屏幕设备上运行它时,它的布局属性会自动改变。 请让我知道是否有任何方法,我可以创建一个单一的布局编程为所有屏幕大小? 我的xml是

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

            <ImageButton
                android:id="@+id/imgBtn1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:background="@drawable/panchangtab1" />

            <ImageButton
                android:id="@+id/imgBtn2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_toRightOf="@+id/imgBtn1"
                android:background="@drawable/horoscopetab1" />
</RelativeLayout>


在这里,我得到的第一个图像是确定的,但第二个图像不是在实际大小

版面的宽度和高度必须使用填充父级、匹配父级、换行内容单位……版面的高度和宽度也必须使用权重,而不是硬编码

检查此链接以查看多屏幕支持布局。。。。。。

请浏览以下网站以开发多屏幕支持应用程序


(也请遵循子链接)

您应该在布局文件中使用“匹配父项”和“换行”内容。在RelativeLayout或LinearLayout或bla-bla中使用它们

如果您想要图像视图、文本视图、按钮。。。如果已覆盖整个屏幕宽度,则应在布局宽度上使用填充父项。另外,如果您想要图像视图、文本视图、按钮。。。如果覆盖了整个屏幕高度,则应在布局高度上使用填充父项


您可以选中此项

您可以使用匹配父项、包装内容、填充父项等。与属性类似,不要创建硬编码布局文件。使用9个补丁图像,不是静态的,不是所有的情况都满足使用9个补丁的条件,但是当您发现一些图像可以在9个补丁中工作时,请使用9个补丁,这仅适用于ImageView,不适用于所有组件、剩余内容TextView、EditText等。您可以自己创建,但不要创建硬编码布局。

它适用于我

在布局声明中使用weightsum将对您有所帮助

       <LinearLayout

                android:weightSum="100"   //This is horizontal layout so will work for width
                android:layout_height="wrap_content"
                android:orientation="horizontal"


                 >

                <EditText
                    android:id="@+id/txt1"
                    android:layout_weight="40" //40% for text1
                    android:layout_height="40dp"  
                    >
                </EditText>

                <EditText
                    android:id="@+id/txt2"
                    android:layout_weight="60" //60% for text2
                    android:layout_height="50dp"  

                    >
                </EditText>
            </LinearLayout>

您可以使用不同的限定符为不同的屏幕创建多个布局,如下所示:

layout-hdpi/mylayout

您应该阅读。

找到屏幕大小,并通过在中设置边距通过代码进行修正java@AshishPatil您不应为应用程序中使用的组件指定任何固定值。请将组件宽度和高度设置为“匹配父级”、“包装内容”、“填充父级”.您知道调整宽度的相对布局吗?对于相对布局,您应该使用匹配父内容和换行内容。