Coder Social home page Coder Social logo

Comments (2)

BaiMingxu avatar BaiMingxu commented on May 29, 2024

设计图尺寸是1366*768

from screenadaptation.

wildma avatar wildma commented on May 29, 2024

@BaiMingxu

由于横屏后,设计图中的宽度对应的就是手机的高度,但是手机的高度碎片化更严重了,像最小宽度适配那样生成多套高度的 dimens.xml 就不合适了。
但是同样可以使用这套适配方案配和文章中说的 “六、其他适配技巧” 达到很好的适配。

也就是说同样使用这套适配方案,依然是以设计图最小宽度(单位为 dp)作为基准值(对应你说的 768 对应的 dp 值),利用插件生成所有设备对应的 dimens.xml 文件。

这样在不同的设备同样会根据设备的最小宽度进行等比缩放,也就达到了适配。只是不能将横屏的宽度全部用固定值写,需要配和文章中说的 “六、其他适配技巧” 来实现。

例如 UI 设计图的宽度为 360dp,设计了横向两个按钮分别位于左右两边,宽度分别是 100dp,240dp,那么这种写法就是错误的:

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

    <Button
        android:layout_width="@dimen/dp_100"
        android:layout_height="wrap_content" />

    <Button
        android:layout_width="@dimen/dp_240"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="@dimen/dp_20" />
</LinearLayout>

这种写法才是正确的:

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

    <Button
        android:layout_width="@dimen/dp_100"
        android:layout_height="wrap_content" />

    <Button
        android:layout_width="@dimen/dp_240"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" />
</RelativeLayout>

from screenadaptation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.