Android 如何设计xml文件以在更多屏幕中显示
我是新的android程序员,我设计了一个4英寸的页面屏幕。我已经用“dp”计量单位初始化。 但当我在10英寸、7英寸或3英寸的屏幕上运行我的项目时,2个组件出错了。Android 如何设计xml文件以在更多屏幕中显示,android,Android,我是新的android程序员,我设计了一个4英寸的页面屏幕。我已经用“dp”计量单位初始化。 但当我在10英寸、7英寸或3英寸的屏幕上运行我的项目时,2个组件出错了。 我了解到dp适用于所有屏幕,但我不知道为什么我的页面不能设置为所有屏幕。如果您可以包含XML文件的任何代码,那将非常有用。 除此之外,我相信您还没有设置android:layout_width和android:layout_height,所以您的XML的其他显示尺寸看起来很奇怪。 加 到您的 e、 g 如果你确实有这个问题,或
我了解到dp适用于所有屏幕,但我不知道为什么我的页面不能设置为所有屏幕。如果您可以包含XML文件的任何代码,那将非常有用。 除此之外,我相信您还没有设置android:layout_width和android:layout_height,所以您的XML的其他显示尺寸看起来很奇怪。 加 到您的
e、 g
如果你确实有这个问题,或者它对你的问题没有帮助
,然后请用您的代码示例进行响应。我的xml文件在这里,但我将一个线性布局的可见性设置为“消失” 当用户触摸按钮时,线性布局将可见,另一个线性布局将消失
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLayout"
android:background="@drawable/darirann"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/layoutTerm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<ScrollView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_marginTop="200dp"
android:layout_height="150dp">
<LinearLayout
android:padding="5dp"
android:layout_width="wrap_content"
android:background="#ffffff"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/firstpageabout" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/btnLoad"
android:layout_gravity="center"
android:textColor="#ffffff"
android:background="#114E7D"
android:gravity="center"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:text="ادامه"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layoutData"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="gone">
<Spinner
android:id="@+id/spState"
android:paddingRight="5dp"
android:layout_gravity="center"
android:background="#D3D3D3"
android:textSize="12sp"
android:layout_marginTop="200dp"
android:layout_width="150dp"
android:gravity="center"
android:layout_height="40dp" />
<Spinner
android:id="@+id/spCity"
android:paddingRight="5dp"
android:layout_gravity="center"
android:background="#D3D3D3"
android:textSize="12sp"
android:gravity="center"
android:layout_marginTop="5dp"
android:layout_width="150dp"
android:layout_height="40dp" />
<Button
android:layout_gravity="center"
android:id="@+id/btnNext"
android:textColor="#ffffff"
android:background="#114E7D"
android:layout_marginTop="10dp"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="مرحله ی بعد" />
<Button
android:layout_gravity="center"
android:id="@+id/btnUpdate"
android:visibility="invisible"
android:textColor="#ffffff"
android:background="#840101"
android:layout_marginTop="80dp"
android:layout_width="200dp"
android:layout_height="40dp"
android:text="دریافت نسخه ی جدید این برنامه" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgAds"
style="?android:attr/buttonStyleSmall"
android:layout_width="150dp"
android:layout_height="75dp"
android:visibility="gone"
android:layout_gravity="center_horizontal|center"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
我使用了Linearlayout,我使用了android:layout\u width=“match\u parent”android:layout\u height=“match\u parent”如果您能在您的问题中给我XML的代码,我将不胜感激。只要把它复制粘贴到这里,你就可以编辑任何你不想让别人看到的东西。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
...
>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLayout"
android:background="@drawable/darirann"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/layoutTerm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<ScrollView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_marginTop="200dp"
android:layout_height="150dp">
<LinearLayout
android:padding="5dp"
android:layout_width="wrap_content"
android:background="#ffffff"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/firstpageabout" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/btnLoad"
android:layout_gravity="center"
android:textColor="#ffffff"
android:background="#114E7D"
android:gravity="center"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:text="ادامه"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layoutData"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="gone">
<Spinner
android:id="@+id/spState"
android:paddingRight="5dp"
android:layout_gravity="center"
android:background="#D3D3D3"
android:textSize="12sp"
android:layout_marginTop="200dp"
android:layout_width="150dp"
android:gravity="center"
android:layout_height="40dp" />
<Spinner
android:id="@+id/spCity"
android:paddingRight="5dp"
android:layout_gravity="center"
android:background="#D3D3D3"
android:textSize="12sp"
android:gravity="center"
android:layout_marginTop="5dp"
android:layout_width="150dp"
android:layout_height="40dp" />
<Button
android:layout_gravity="center"
android:id="@+id/btnNext"
android:textColor="#ffffff"
android:background="#114E7D"
android:layout_marginTop="10dp"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="مرحله ی بعد" />
<Button
android:layout_gravity="center"
android:id="@+id/btnUpdate"
android:visibility="invisible"
android:textColor="#ffffff"
android:background="#840101"
android:layout_marginTop="80dp"
android:layout_width="200dp"
android:layout_height="40dp"
android:text="دریافت نسخه ی جدید این برنامه" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgAds"
style="?android:attr/buttonStyleSmall"
android:layout_width="150dp"
android:layout_height="75dp"
android:visibility="gone"
android:layout_gravity="center_horizontal|center"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>