【问题标题】:Android design for all screen size and resolution适用于所有屏幕尺寸和分辨率的 Android 设计
【发布时间】:2016-03-11 21:03:47
【问题描述】:

您好,我正在开发一个包含此 design 的应用程序。通过大量的努力,我开发了this。但这仍然与给定的设计不同,在其他屏幕上我得到了this。这是xml文件中的代码。任何帮助将不胜感激。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@mipmap/dashboard_bg"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@null"
            android:src="@mipmap/logo" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@null"
            android:src="@mipmap/logo" />
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="Welcome text of app" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="bottom" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:contentDescription="@null"
            android:src="@mipmap/seperator" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_above="@+id/imageView1"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:contentDescription="@null"
            android:src="@mipmap/regional_managers" />

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageView3"
            android:layout_toEndOf="@+id/imageView1"
            android:layout_toRightOf="@+id/imageView1"
            android:contentDescription="@null"
            android:src="@mipmap/regions" />

        <ImageView
            android:id="@+id/imageView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/imageView3"
           android:layout_alignEnd="@+id/imageView3"
            android:layout_below="@+id/imageView4"
            android:contentDescription="@null"
            android:src="@mipmap/graphs" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_alignTop="@+id/imageView1"
            android:layout_toLeftOf="@+id/imageView1"
            android:layout_toStartOf="@+id/imageView1"
            android:contentDescription="@null"
            android:src="@mipmap/nationwide" />

    </RelativeLayout>

</LinearLayout>

还尝试了来自 so like 的链接 image size (drawable-hdpi/ldpi/mdpi/xhdpi)Setting drawable folder to use for different resolutions 但无法获得预期的结果。任何帮助将不胜感激。

【问题讨论】:

  • 我建议您使用百分比相对布局 (developer.android.com/reference/android/support/percent/…) 在屏幕上放置任何大小的东西。但更好的选择是采用 Android 范例,为您的导航选项提供一个导航抽屉,而不是浮动按钮呢?
  • 你试过把图片放在drawable-xxxhdpi/xxhdpi/hdpi/mdpi文件夹吗?
  • @Francesc 我很想使用 android 范例。但浮动按钮是用户要求。
  • @ShadabAnsari 是的,我按照标准 ldpi | mdpi | tvdpi |高清晰度电视 | xhdpi | xxhdpi | xxxhdpi 0.75 | 1 | 1.33 | 1.5 | 2 | 3 | 4

标签: android android-layout android-linearlayout android-drawable android-relativelayout


【解决方案1】:

试试这样的:

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        app:layout_marginTopPercent="10%"
        app:layout_widthPercent="30%" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_marginLeftPercent="20%"
        app:layout_marginTopPercent="40%"
        app:layout_widthPercent="20%" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_marginLeftPercent="60%"
        app:layout_marginTopPercent="55%"
        app:layout_widthPercent="20%" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_marginLeftPercent="30%"
        app:layout_marginTopPercent="70%"
        app:layout_widthPercent="20%" />

</android.support.percent.PercentRelativeLayout>

【讨论】:

  • 我不知道百分比相对布局。但是在您发表评论后,上面的答案和谷歌文档我能够为除 Nexus 9 和 10 之外的所有布局获得所需的结果。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-06
  • 2011-11-15
  • 1970-01-01
相关资源
最近更新 更多