1

Я новичок в Android-программировании, я только что опубликовал приложение на playstore и узнал, что несколько кнопок, которые я установил в свой макет, не отображаются на некоторых устройствах. Как я могу убедиться, что он совместим с различными устройствами? Следует избегать использования относительной компоновки. Вот макет, где кнопка «Создать учетную запись» отображается на вкладке Galaxy, Nexus 4 и 5, но не на Galaxy Grand.Как поддерживать формат Android на разных устройствах?

<?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> 
+0

см это http://stackoverflow.com/questions/28821850/my-layout-gets-messy-whenever-i-open-it-in-the-emulator-its-a-background- image/28846829 # 28846829 –

+0

или это http://stackoverflow.com/questions/29025843/android-devices-with-different-height-takes-same-layout-folder –

+0

С одной стороны, нет ничего плохого в использовании относительных макетов если вы не можете выполнить что-то, используя только линейный макет. С другой стороны, вы должны стараться максимально уменьшить глубину ваших макетов. В этом случае два относительных макета верхнего уровня не нужны, полная потеря времени компоновки макета. – AndroidEx

ответ

0

Пересмотреть свой дизайн и предоставить восхитительный опыт для ваших пользователей.

Вам нужно сосредоточиться на некоторых областях изменчивости на устройствах Android и о том, как эти изменения влияют на разработку и дизайн приложений для Android.

  1. Схема установки
  2. Размер, Отступы и поля
  3. Общие Макеты
  4. ресурсов Отборочные
  5. Split Просмотров

Вывод:

если ваш поводу с одним экраном компоновка, чем использование линейного макета с весами , OFFICIAL Example:

<?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" /> 

другое использование прокрутки-возможности раскладки, как взгляд ListView карты с realitivelayout для каждой строки, потому что это более эффективно.

P.S. У вас много ненужных атрибутов, установленных в xml. Я просто сделал это за несколько секунд, чтобы помочь вам. Вы должны прочитать, как работают RelativeLayout и LinearLayout. Дополнительных знаний прочитать official documents

0

Я рекомендую вам прочитать, что эти страницы: http://www.google.com/design/spec/layout/metrics-keylines.html

Там у вас есть рекомендации по проектированию для создания приложений для настольных, планшетных ПК и телефона.

О коде, вам нужно только создать макеты для каждого устройства (обычно это планшет и телефон, либо добавить телевизор и износ).

Смежные вопросы