【问题标题】:Android layout design for mobile and tablet with Vector drawable as background以 Vector drawable 为背景的手机和平板电脑的 Android 布局设计
【发布时间】:2020-09-10 10:40:48
【问题描述】:

有人可以建议我设计 android 布局以支持移动设备和平板电脑的最佳方法。 附上 3 种不同设备的屏幕截图(2 台平板电脑和 1 台手机)

我使用 layout-sw600dp 来支持 al 平板电脑。我希望这下的所有布局都能加载到最小宽度为 600dp(即最小边)的平板电脑上

问题:这是为移动设备和平板电脑分开布局的正确方法吗?

我遇到的一个问题是矢量 xml 文件在涉及到平板电脑时会被拉伸(我在下面附上了矢量 xml 代码)

<vector xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:aapt="http://schemas.android.com/aapt"
  android:width="360dp"
  android:height="640dp"
  android:viewportWidth="360"
  android:viewportHeight="640">
<path
    android:pathData="M0,0h360v640h-360z"
    android:fillColor="#fff"/>
<path
    android:pathData="M0.001,0h360v10.634l-360,207.846Z">
  <aapt:attr name="android:fillColor">
    <gradient 
        android:startY="6.1174397"
        android:startX="309.601"
        android:endY="58.989597"
        android:endX="-134.99901"
        android:type="linear">
      <item android:offset="0" android:color="#FFFFB88C"/>
      <item android:offset="1" android:color="#FFDE6262"/>
    </gradient>
  </aapt:attr>
</path>
<path
    android:pathData="M70.674,0L360,0L360,501.127Z">
  <aapt:attr name="android:fillColor">
    <gradient 
        android:startY="-30.568748"
        android:startX="197.39879"
        android:endY="501.127"
        android:endX="387.7753"
        android:type="linear">
      <item android:offset="0" android:color="#FFDE6262"/>
      <item android:offset="1" android:color="#FFFFB88C"/>
    </gradient>
  </aapt:attr>
</path>

添加 svg 图像的矢量 xml 文件的正确方法是什么。我需要这个 xml 文件的多个版本吗(如果需要,匹配不同屏幕大小的命名约定是什么) 我想我以前做过这个但会导致重复的 xml 错误(即当我将它添加到 drawable-ldpi、xhdpi 等时)

有人可以建议我在上述情况下为 android 布局提供最佳解决方案

提前致谢

【问题讨论】:

    标签: android xml android-layout svg layout


    【解决方案1】:

    使用 SDP 库这里是链接 https://github.com/intuit/sdp 您不必担心为不同的屏幕尺寸创建不同的布局,它会适合自己。

    【讨论】:

    • 被拉伸的矢量 xml 文件怎么办?
    • 我尝试了 sdp 但没有按预期工作,例如全宽的文本字段在移动设备上看起来不错,但在大屏幕上看起来很糟糕.. 即用于带有电子邮件和密码的登录页面
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    相关资源
    最近更新 更多