我是Android编程的新手,但我知道一切都起作用,最近我试图创建一个像Uber这样的应用程序,就像Uber创建启动活动后,我在实际设备上对其进行了测试要检查一切看起来是否还不错,但是当我在设备上启动它时,所有内容(布局,imageviews,textViews..Etc)都放错了位置,这次我从来没有遇到过这个问题。谁能告诉我我要去哪里?我在下面附上屏幕截图。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#ffffff"
tools:context="com.example.keyur.uber.MainActivity">
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/layout1"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/showtext"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:fontFamily="monospace"
android:text="@string/get_moving_with_uber"
android:textColor="#000000"
android:textSize="20sp"
android:typeface="monospace" />
<ImageView
android:layout_width="40dp"
android:id="@+id/imgv"
android:layout_height="30dp"
android:layout_below="@id/showtext"
android:layout_marginLeft="30dp"
android:background="@drawable/india"
/>
<TextView
android:layout_width="40dp"
android:id="@+id/countrycode"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginStart="13dp"
android:layout_toEndOf="@+id/imgv"
android:text="@string/_91"
android:textColor="#000000"
android:textSize="22sp"
android:fontFamily="monospace"
/>
<EditText
android:id="@+id/editText"
android:layout_width="250dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="#ffffff"
android:fontFamily="monospace"
android:hint="@string/enter_your_mobile_number"
android:textColor="#000000"
android:textColorHint="#484848"
android:textSize="17sp"
android:inputType="number"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="400dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgone"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/layoutbg" />
</RelativeLayout>
</LinearLayout>
屏幕截图 - 这就是应用程序在像素4上的外观,因为它在默认情况下设置了。在此处输入图像描述
这就是我将其切换到Pixel XL时的外观,一切都变得混乱
在此处输入图像描述
到期是否要修复布局 hight an width ,因此每个设备都具有不同的屏幕尺寸。您应该使用match_parent
和wrap_content
。如果要以相同的方式将所有设备空间拆分,则必须使用 wigith 。
如何使用权重参考
您可以选择"重量总和" ,或者应该设置您的
TextView
for country-code " layout_torightof" to Image视图 而不是" layout_toendof" 。