【问题标题】:Testing my layout on all devices在所有设备上测试我的布局
【发布时间】:2023-03-03 12:23:01
【问题描述】:

我想在所有设备上测试我的布局,因为在小型设备上看不到我的布局。

有什么网站或工具可以帮助我吗?

请提出建议。

以下是主要活动的 xml 布局。它适用于大屏幕手机,但不适用于小屏幕。

布局包含gridview + fab button + adview

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"
    tools:ignore="Overdraw">


    <LinearLayout
        android:layout_marginTop="15dp"
        android:layout_marginBottom="10dp"
        android:id="@+id/hideMenu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bottomBox"
        android:layout_alignParentStart="true"
        android:gravity="center"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/submittedstatus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:contentDescription="@string/statusdesc"
            android:padding="5dp"
            android:visibility="invisible"
            ads:srcCompat="@drawable/status" />

        <ImageButton
            android:id="@+id/submittedImg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:contentDescription="@string/ImageContent"
            android:padding="5dp"
            android:visibility="invisible"
            ads:srcCompat="@drawable/image" />

        <ImageButton
            android:id="@+id/submittedPost"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:contentDescription="@string/postdesc"
            android:padding="5dp"
            android:visibility="invisible"
            ads:srcCompat="@drawable/post" />


        <android.support.design.widget.FloatingActionButton

            android:id="@+id/fab"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:background="@android:color/transparent"
            android:foregroundGravity="center"
            app:backgroundTint="@color/colorPrimary"
            app:srcCompat="@drawable/sharewhite" />

        <ImageButton
            android:id="@+id/addpersonality"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:contentDescription="@string/personality"
            android:padding="5dp"
            android:visibility="invisible"
            ads:srcCompat="@drawable/personality" />

        <ImageButton
            android:id="@+id/addfort"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:contentDescription="@string/fort"
            android:padding="5dp"
            android:visibility="invisible"
            ads:srcCompat="@drawable/fort" />


        <ImageButton
            android:id="@+id/addwar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:contentDescription="@string/war"
            android:padding="5dp"
            android:visibility="invisible"
            ads:srcCompat="@drawable/war" />


    </LinearLayout>

    <GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:numColumns="3"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="160dp">


    </GridView>

    <LinearLayout
        android:id="@+id/bottomBox"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:background="@android:color/white"
        android:gravity="center"
        android:weightSum="1">


        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            ads:adSize="LARGE_BANNER"
            android:layout_height="wrap_content"
            ads:adUnitId="@string/banner_home_footer">

        </com.google.android.gms.ads.AdView>



    </LinearLayout>




</RelativeLayout>

【问题讨论】:

  • 添加一些布局细节
  • 感谢您的回复
  • 我有未更新的带有 xml 代码的帖子。请建议

标签: android android-layout android-linearlayout


【解决方案1】:

在 Android Studio 的布局编辑器中,您可以模拟不同的屏幕尺寸并查看布局在每种屏幕尺寸下的显示方式

https://developer.android.com/studio/write/layout-editor.html#change-appearance

【讨论】:

  • 谢谢 shmuel,一定会试试这个
  • 不客气。如果这解决了您的问题,请将其标记为答案以供将来参考。
【解决方案2】:

检查不同手机布局的最简单方法是使用编辑器中的设备设置并选择您要试用的手机。您可以通过选择要检查的 xml 文件来达到此设置,然后按左下角的设计选项卡。然后,该设置在设计器视图中的布局上方可见。您还可以添加列表中不可见的其他手机。

【讨论】:

    【解决方案3】:

    @酷把戏 编辑布局时,android studio 中的右上角有预览选项卡。

    这是一个非常酷的菜单选项卡,您可以根据需要配置设备。

    干杯!!

    假设您想为暴民和大型设备的相同布局创建不同的属性,那么您可以使用相同的名称布局。只需再创建一个文件夹“layout-large”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多