Android tvdpi vs xhdpi screen issue

痴心易碎 提交于 2019-12-13 05:53:49

问题


I'm developing an app for a tablet which until recently was tested in an emulator for Nexus 7 (7.27'',800x1280:tvdpi). Everything was fine until I decided to test the app in a different emulator, one created similar to samsung galaxy note 2 (5.6'',720x1280:xhdpi) and it doesn't look so well.

For example, take a look at this custom alert dialog I'm using.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/dialog_layout_root"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="10dp"
          android:background="@color/light_gray">
         <Button
             android:id="@+id/facebook_login_button"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerHorizontal="true"
             android:layout_marginTop="40dp"/>
         <TextView
             android:id="@+id/or_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textIsSelectable="true"
             android:layout_centerHorizontal="true"
             android:layout_marginTop="20dp"
             android:textSize="20sp"
             android:textColor="@color/black"
             android:layout_below="@id/facebook_login_button"/>
         <TextView
             android:id="@+id/sign_in_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textIsSelectable="true"
             android:layout_marginLeft="10dp"
             android:layout_marginTop="20dp"
             android:textSize="20sp"
             android:textColor="@color/gray"
             android:layout_below="@id/or_text"/>
         <EditText
             android:id="@+id/login_email"
             android:layout_width="320dp"
             android:layout_height="wrap_content"
             android:layout_marginLeft="10dp"
             android:layout_below="@id/sign_in_text"
             android:hint="@string/email_login"
             android:inputType="textEmailAddress"/>
         <EditText
             android:id="@+id/login_password"
             android:layout_width="320dp"
             android:layout_height="wrap_content"
             android:layout_marginLeft="10dp"
             android:layout_below="@id/login_email"
             android:hint="@string/pass_login"
             android:inputType="textPassword"/>
         <TextView
             android:id="@+id/case_sensitive_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textIsSelectable="true"
             android:layout_marginLeft="10dp"
             android:layout_marginTop="20dp"
             android:textSize="18sp"
             android:textColor="@color/gray"
             android:layout_below="@id/login_password"/>
         <CheckBox
             android:id="@+id/remember_login"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textColor="@color/black"
             android:layout_below="@id/case_sensitive_text"/>
         <Button
             android:id="@+id/sign_in_button"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_below="@id/remember_login"
             android:layout_marginLeft="300dp"/>
         <TextView
             android:id="@+id/forget_password_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textIsSelectable="true"
             android:layout_marginLeft="180dp"
             android:textSize="18sp"
             android:textColor="@color/black"
             android:layout_below="@id/sign_in_button"/>
         <View
            android:id="@+id/horizontal_line"
            android:layout_width="360dp"
            android:layout_marginTop="20dp"
            android:layout_height="1dp"
            android:background="@android:color/darker_gray"
            android:layout_below="@id/forget_password_text"/>
         <TextView
             android:id="@+id/new_app_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textIsSelectable="true"
             android:textSize="18sp"
             android:textColor="@color/black"
             android:layout_below="@id/horizontal_line"/>
         <TextView
             android:id="@+id/create_account_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textIsSelectable="true"
             android:textSize="18sp"
             android:textColor="@color/gray"
             android:layout_below="@id/new_app_text"/>
         <Button 
             android:id="@+id/create_account_button"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_below="@id/create_account_text"
             android:layout_marginLeft="250dp"
             android:layout_marginTop="10dp"/>
         <TextView
             android:id="@+id/terms_conditions_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textIsSelectable="true"
             android:textSize="12sp"
             android:textColor="@color/gray"
             android:layout_below="@id/create_account_button"/>
         <TextView
             android:id="@+id/vertical_rule"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textIsSelectable="true"
             android:textSize="12sp"
             android:textColor="@color/gray"
             android:layout_below="@id/create_account_button"
             android:layout_toRightOf="@id/terms_conditions_text"/>
         <TextView
             android:id="@+id/privacy_policy_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textIsSelectable="true"
             android:textSize="12sp"
             android:textColor="@color/gray"
             android:layout_below="@id/create_account_button"
             android:layout_toRightOf="@id/vertical_rule"/>             
</RelativeLayout>

As you can see I'm using Relative Layout and I use dp everywhere and sp for font size. If you notice on the background of the alert dialog not even the fragments are displaying correct. You can take a look here: http://imageshack.us/g/692/tvdpi.jpg/

Any suggestions why is this happening?

Thanks in advance.


回答1:


You can create different Drawable folder for tvdpi images like drawable-tvdpi and drawable-xhdpi is already created if you use eclipse . Keep diffrent images accourding to their density.

Note also create different layout folder for Nexus7 and samsung galaxy note .

Example layout-sw600dp for nexus-7 and layout-sw360dpi for Galaxy nexus .

Keep your layout files in both folders.

This will work :)



来源:https://stackoverflow.com/questions/16028697/android-tvdpi-vs-xhdpi-screen-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!