如何在各种设备上保持Android布局的一致性?
我是Android编程新手,我刚刚在playstore上发布了一个应用程序,发现我在布局中放置的几个按钮在一些设备上没有显示出来。我如何确保它在不同的设备上是一致的? 我应该避免使用相对布局吗。 这是创建帐户按钮显示在Galaxy选项卡、Nexus 4和5上的布局,但不显示在Galaxy Grand上如何在各种设备上保持Android布局的一致性?,android,user-interface,android-linearlayout,android-relativelayout,Android,User Interface,Android Linearlayout,Android Relativelayout,我是Android编程新手,我刚刚在playstore上发布了一个应用程序,发现我在布局中放置的几个按钮在一些设备上没有显示出来。我如何确保它在不同的设备上是一致的? 我应该避免使用相对布局吗。 这是创建帐户按钮显示在Galaxy选项卡、Nexus 4和5上的布局,但不显示在Galaxy Grand上 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.andr
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/background">
<RelativeLayout android:id="@+id/container" android:layout_width="match_parent"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
android:layout_height="match_parent"
android:background="#85000000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:orientation="vertical"
android:layout_centerHorizontal="true"
android:id="@+id/linearLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="95dp"
android:layout_marginBottom="10dp"
android:hint="@string/email"
android:textColor="#fd9a22"
android:textCursorDrawable="@drawable/cursor_color"
android:textColorHint="#ffffff"
android:id="@+id/txtUser"
android:background="@drawable/edit_text"
android:drawableLeft="@drawable/dr_email"
android:drawablePadding="10dp"
android:paddingLeft="-3dp"
android:singleLine="true"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="match_parent"
android:inputType="textPassword"
android:layout_height="wrap_content"
android:id="@+id/txtPwd"
android:hint="@string/pwd"
android:textColor="#fd9a22"
android:textCursorDrawable="@drawable/cursor_color"
android:textColorHint="#ffffff"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:background="@drawable/edit_text"
android:drawableLeft="@drawable/dr_pwd"
android:drawablePadding="10dp"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content"
android:text="@string/sign_in"
android:id="@+id/btnSignIn"
android:background="@drawable/ainovatheme_btn_default_holo_light"
android:onClick="login"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#fd9a22"
android:background="#85000000"
android:id="@+id/txtLoginErr"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/forgot_pwd"
android:textColor="#ffffff"
android:id="@+id/btnForgotPwd"
android:layout_gravity="center_horizontal"
android:onClick="forgotPassword"
style="?android:attr/borderlessButtonStyle"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="3dp"
android:background="#d4dce9" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:text="@string/create_account"
android:textColor="#fd9a22"
android:id="@+id/btnCreateAccountActivity"
android:onClick="createAccount"
style="?android:attr/borderlessButtonStyle"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
重新思考您的设计,为用户提供愉悦的体验 您需要关注Android设备中的一些变化领域,以及这些变化如何影响Android应用程序的开发和设计
否则,将可滚动布局(如listview card view)与realictiveLayout一起用于每一行,因为这样效率更高
另外,您在xml中设置了许多不必要的属性。。我只是在几秒钟内做了这件事来帮助你。您应该阅读RelativeLayout和LinearLayout的工作原理。
有关更多知识,请阅读我建议您阅读以下页面: 在这里,您有一个为桌面、平板电脑和手机创建应用程序的设计指南
关于代码,您只需要为每个设备创建布局(通常是平板电脑和手机,或者添加太多的电视和服装) 您可以使用PercentRelativeLayout,在其中可以使用百分比设置位置、大小和边距。检查下面的链接
一方面,如果仅使用线性布局无法完成某些任务,那么使用相对布局也没有什么坏处。另一方面,您应该尽量减少布局的深度。在这种情况下,两个上层相对布局是不必要的,完全浪费了布局绘图时间
<?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:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/to" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/subject" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="@string/message" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/send" />