当前位置: 首页 > 知识库问答 >
问题:

需要相同的设计为不同类型的设备在Android

尉迟雅昶
2023-03-14

我创建了一个如图所示的按钮布局设计。如何实现不同尺寸屏幕的设计模式?这种布局适合3.7英寸屏幕,但不适合其他屏幕。可能是scrollview是一个选项,但这并不满足我。我怎么能做到呢?有什么帮助吗?

这是我的xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="110dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="5dp"
    android:text="Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="110dp"
    android:layout_below="@+id/button1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="5dp"
    android:text="Button" />

<Button
    android:id="@+id/button3"
    android:layout_width="match_parent"
    android:layout_height="110dp"
    android:layout_below="@+id/button2"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="5dp"
    android:text="Button" />

<Button
    android:id="@+id/button4"
    android:layout_width="match_parent"
    android:layout_height="110dp"
    android:layout_below="@+id/button3"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="5dp"
    android:text="Button"
    android:layout_marginBottom="5dp" />

共有1个答案

荀金鹏
2023-03-14

嗨,你可以用重量代替相对布局。。如果你使用相对布局的概念,它将适合所有屏幕。尝试下面的xml,并在不同的屏幕上进行检查。

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
      android:orientation="vertical"
   android:weightSum="8" >

     <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="0dp"
   android:layout_weight="2"
android:text="Button" />

  <Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:text="Button" />

  <Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="0dp"
  android:layout_weight="2"
android:text="Button" />

   <Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="0dp"
  android:layout_weight="2"
android:text="Button"
 />
</LinearLayout>

线性布局中的权重总和将取整个屏幕大小。layout_weight会根据重量修理按钮...

 类似资料:
  • 我需要编写一个java方法来从一个对象中获取特定的信息。但是,该对象可以是A类型的,也可以是B类型的。下面是我的代码的一部分: 当我这样写它时,它会引发一个错误,说“重复方法”。我怎么才能让这个起作用?

  • 这是一个面向对象设计模式专家的问题。 假设我有一个类,负责读取/解析数据流(携带不同类型的信息包)。每个数据包都携带不同类型的信息,因此理想情况下,我会为每种类型的数据包创建一个类(,,…每个都有自己的接口)。 然后,方法将遍历流,并将类(或指向类的指针或引用)返回到相应的包类型。 你会用空指针吗?一个泛型类()可以提供一个公共(部分)接口来查询数据包的类型(这样就可以在运行时做出任何决定),怎么

  • 我正在尝试使用Intent打开文件。操作\u获取\u类似于此帖子的内容: Android打开一个文件与ACTION_GET_CONTENT结果到不同的Uri的 但是这里只是一个解决方案,如何使用不同的SDK/文件夹获取文件名,而不是不同的设备。获得Uri的意图也保持不变。 我想开门。png文件。 Uri.getPath()为两个设备(都. png文件存储在下载文件夹): 因此,问题是,如果我使用

  • 我的第一个Android应用程序。而且,我正在努力解决这个问题- 然后我放了一个十美分硬币。xml 唷!但这还不够。我想有不同的文本大小(和其他尺寸,我不在这里谈论图像)的手机 下面是我正在做的一个例子: 然后在迪蒙斯。xml,应该是:17 这个值,即这里的17,将在每个设备中不同,即它在每个值文件夹下的每个dimens.xml中被赋予不同的值。我希望是清楚的。

  • Firebase A/B测试是否考虑由设置的用户id?下面是我的用例: 打开应用程序 他签入 用调用 获取远程配置值->他登陆 在其他设备(相同的Google帐户)上打开应用程序 他签入 用调用 获取远程配置值->是否保证他将登陆? 对A/B测试有意义吗?

  • 在android中是否有区分不同类型的音频设备?例如,我从不同的制造商获得了音频设备类型A和音频设备类型B,这两种设备都使用音频插孔。每当用户插入音频设备类型A或类型B时,我想知道设备ID或名称、类型。我可以使用BroadcastRecencer检测音频设备的插入/输出。但无法获取设备ID或名称或类型。场景是:当音频设备类型A连接时,开启服务A,当音频设备类型B连接时,开启服务B。