【问题标题】:Android: Design for different screen sizes but with same DPIAndroid:针对不同屏幕尺寸但具有相同 DPI 的设计
【发布时间】:2016-02-25 10:16:34
【问题描述】:

我设计了一个布局并将其放置在 layout 文件夹中。 我有三星 s3 和 Nexus 4,它们具有相同的 DPI,即 Xhdpi。 但是当我运行应用程序时,s3 完美地显示了布局,但在 nexus 4 中我丢失了一些项目。现在我为 nexus4 设计了布局,并将其放在 Layout-xhdpi 文件夹中。现在 s3 在访问 xhdpi 文件夹时被扭曲了。

下面是我的布局

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

如何在所有屏幕尺寸不同但 dpi 相同的设备上也能做到这一点

【问题讨论】:

标签: android android-layout hdpi


【解决方案1】:

https://github.com/intuit/sdp

在您的应用中试用此库。每种尺寸都有 dps。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    相关资源
    最近更新 更多