android - android中不同类型的设备需要相同的设计

标签 android design-patterns layout

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

enter image description here

这是我的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" />

最佳答案

您好,您可以使用权重而不是相对布局。如果您使用相对布局概念,它将适合所有屏幕。 试试下面的 xml 并在不同的屏幕上 checkin 。

   <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 将根据权重固定按钮..

关于android - android中不同类型的设备需要相同的设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15515791/

相关文章:

android - 连接到 ros master

c# - 当您还需要 "default"具体依赖项时,哪种依赖项注入(inject)更好的模式?

python - 如何避免函数名称中的参数类型?

css - 上移内联显示的字符

android - 包含在 Eclipse 中用于抛出 "no resource found"的布局

android - TextView 内的 TextView

android - 如何将现有的 MS Access 移植到 SQLite 以用于 Android 应用程序开发?

android - 如何在 Android 中使用 CheckBox 跟踪 ListView 中选中的行

android - 在没有模拟器的情况下在 2GB RAM 中运行 Android Studio

C# Helper 模式与服务方法