简体   繁体   English

Android:针对不同的屏幕尺寸但具有相同的DPI进行设计

[英]Android: Design for different screen sizes but with same DPI

I Designed a layout and placed it it the layout folder. 我设计了一个布局并将其放置在布局文件夹中。 I have samsung s3 and Nexus 4 which has the same DPI which is Xhdpi. 我有三星s3和Nexus 4,它们具有相同的DPI,即Xhdpi。 But when i am running the app s3 shows layout perfectly but in nexus 4 i am loosing some items. 但是,当我运行应用程序s3时,它可以完美显示布局,但在nexus 4中,我丢失了一些物品。 Now i designed layout for nexus4 and placed it in Layout-xhdpi folder . 现在,我为nexus4设计了布局,并将其放置在Layout-xhdpi文件夹中。 Now s3 is distorted as it is accessing the xhdpi folder. 现在s3在访问xhdpi文件夹时已失真。

Below is my layout 下面是我的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/toplayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#fff" >
  <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="vertical"
    android:layout_weight="1" >
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
    android:layout_marginLeft="7.5dp"
    android:layout_marginRight="7.5dp"
    android:layout_marginBottom="3dp"
    android:layout_marginTop="20dp"
    android:focusable="true" 
    android:focusableInTouchMode="true">
    <TextView
        android:id="@+id/title_bore"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/tolerancebore" 
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:textSize="17sp"/>
    <TextView
        android:id="@+id/boreselect"
        android:layout_width="0dp"
        android:layout_height="36dp"
        android:text="@string/select"
         android:layout_weight="1"
         android:drawableEnd="@drawable/arrow" 
         android:background="@drawable/edittext_select"
         android:ems="10"
         android:paddingLeft="10dp"
         android:paddingRight="5dp"
         android:gravity="center_vertical"
         android:textColor="#d1d3d3" />
</LinearLayout>
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginLeft="7.5dp"
    android:layout_marginRight="7.5dp"
    android:layout_marginTop="25dp">
    <TextView
        android:id="@+id/title_shaft"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/toleranceshaft" 
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
         android:textSize="17sp"  />
    <TextView
        android:id="@+id/shaftselect"
        android:layout_width="0dp"
        android:layout_height="36dp"
        android:text="@string/select"
        android:layout_weight="1" 
        android:drawableRight="@drawable/arrow"
        android:background="@drawable/edittext_select"
        android:ems="10"
        android:paddingLeft="10dp"
        android:paddingRight="5dp" 
        android:gravity="center_vertical"
         android:textColor="#d1d3d3" />
</LinearLayout>

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="80dp"
     android:background="#f8f8f8" 
     android:layout_marginRight="7.5dp"
     android:layout_marginLeft="7.5dp"
     android:layout_marginTop="25dp"
    >

        <LinearLayout 
    android:id="@+id/relfst"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
   android:layout_centerVertical="true" >
    <TextView
        android:id="@+id/title_nominal"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/nominalsize" 
        android:layout_weight="1"
      android:layout_gravity="center_vertical"
       android:textSize="17sp"
    />


<FrameLayout
     android:id="@+id/frame"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="1" >
<TextView
            android:id="@+id/unit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center_vertical"
            android:gravity="center"
            android:text="in"
            android:paddingRight="5dp" />
       <EditText
            android:id="@+id/nominalsize"
            android:layout_width="match_parent"
            android:layout_height="36dp"
            android:ems="10"
            android:background="@drawable/edittext_select"
            android:labelFor="@+id/editText"
            android:layout_gravity="start|center_vertical"
            android:gravity="start|center_vertical"
            android:focusable="false"
            android:cursorVisible="false"
            android:singleLine="true"
            android:paddingLeft="3dp"
            android:maxLength="12">

            </EditText>


</FrameLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout 
     android:id="@+id/banner"
    android:layout_width="match_parent"
    android:layout_height="25dp"
    android:orientation="horizontal"
     android:background="#dedddb" 
     android:visibility="invisible"  
     android:layout_marginRight="7.5dp"
     android:layout_marginLeft="7.5dp"
   >   
     <TextView
        android:id="@+id/text_fits_msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/range_msg" 
       android:layout_gravity="center_vertical"
        android:layout_centerInParent="true"
        android:paddingStart="5dp"/>

     <ImageView
         android:id="@+id/infoicon"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignBottom="@+id/text_fits_msg"
         android:layout_toLeftOf="@+id/text_fits_msg"
         android:layout_toStartOf="@id/text_fits_msg"
         android:src="@drawable/info" 
         android:layout_marginBottom="1dp"/>

   </RelativeLayout>
<RelativeLayout 
     android:id="@+id/rel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
<RelativeLayout 

    android:layout_width="match_parent"
    android:layout_height="match_parent"
  android:layout_alignParentBottom="true"
   android:layout_centerHorizontal="true">
 <include
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/sample"
       android:layout_marginLeft="7.5dp"
       android:layout_marginRight="7.5dp"
         android:layout_marginTop="10dp" />


 <include
        android:id="@+id/header1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/sample1"
        android:layout_below="@id/header" 
        android:layout_marginTop="20dp"
    android:layout_marginLeft="7.5dp"
    android:layout_marginRight="7.5dp"
  />

  <include
      android:id="@+id/header2"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      layout="@layout/sample2"
    android:layout_marginLeft="7.5dp"
    android:layout_marginRight="7.5dp"
    android:layout_marginBottom="10dp" 
      android:layout_marginTop="20dp"
     android:layout_below="@id/header1" />

 </RelativeLayout>
  </RelativeLayout>
</LinearLayout>
<android.inputmethodservice.KeyboardView
        android:id="@+id/keyboardview"
        style="@style/unit_conv_frag_keyboard"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fadingEdge="none"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:radius="5dp"
        android:visibility="gone" />
</LinearLayout>

How to make it even in all devices with different screen sizes but same dpi 即使在屏幕尺寸不同但dpi相同的所有设备中如何制作

https://github.com/intuit/sdp https://github.com/intuit/sdp

try this library in your app. 在您的应用中尝试该库。 It have dps for every size. 每个尺寸都有dps。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM