问题描述
我有一个菜单屏幕XML.当我打开项目宽屏时,它不能适应所有屏幕尺寸.我该如何克服这个问题.
I have an menuscreen XML. When I open the project wide screen Its not adapted all screen size. How can I overcome this problem.
当我想添加有关此问题的图片时,我认为我需要10名代表.点:)
When I want to add picture about this problem I think I need 10 rep. point :)
有人可以帮助我吗?
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/samsun"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:text="@string/samsun"
android:textColor="#FFFF" />
<Button
android:id="@+id/trabzon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:text="@string/trabzon"
android:textColor="#FFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/adana"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:text="@string/adana"
android:textColor="#FFFF" />
<Button
android:id="@+id/antalya"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:text="@string/antalya"
android:textColor="#FFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/izmir"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/izmir"
android:textColor="#FFFF" />
<Button
android:id="@+id/bursa"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/bursa"
android:textColor="#FFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/istanbul1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/gayrettepe"
android:textColor="#FFFF" />
<Button
android:id="@+id/istanbul2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/acibadem"
android:textColor="#FFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/erzurum"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/erzurum"
android:textColor="#FFFF" />
<Button
android:id="@+id/diyarbakir"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/diyarbakir"
android:textColor="#FFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/ankara"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/ankara"
android:textColor="#FFFF" />
<Button
android:id="@+id/kayseri"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/kayseri"
android:textColor="#FFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/alcatel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/alcatel"
android:textColor="#FFFF" />
<Button
android:id="@+id/huawei"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/huawei"
android:textColor="#FFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/backbone"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/backbone"
android:textColor="#FFFF" />
</LinearLayout>
</LinearLayout>
推荐答案
在android中,要支持尽可能多的设备,可以为一个布局提供多个定义.首先,您需要将这些文件夹添加到资源中,并为每个文件夹指定相同布局的不同xml文件,以满足您希望在其上使用应用程序的设备屏幕.
In android, to support as much devices as possible, you can supply multiple definitions of one layout. First you need to add those folders into your resources, and for each one you can specify different xml files of the same layout to meet the device screens you want your app to be used on.
下面是一个有关文件夹结构的示例:
Here is an example on how the folder structure might look like:
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/layout/main_activity.xml // For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml // For 7" tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml // For 10" tablets (720dp wide and bigger)
(在应用清单中)
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
有关支持多个屏幕的更多信息,我强烈建议阅读有关它的google文档. 此处是文档的链接. http://developer.android.com/guide/practices/screens_support.html
For more info on supporting multiple screens i strongly recommend reading the google docs about it. Here is a link to the documents. http://developer.android.com/guide/practices/screens_support.html
这篇关于我的项目不支持多个设备的屏幕视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!