【问题标题】:Android: Buttons Orientation for different screen sizesAndroid:不同屏幕尺寸的按钮方向
【发布时间】:2014-02-08 03:55:56
【问题描述】:

我的按钮布局有问题。

我制作了“small, normal, large, xlarge”布局文件夹。

但在某些设备上,按钮仍然混合在一起!

当我使用设备集 eclipse 查看我的布局时,我可以看到问题,但我不知道设备的尺寸是多少。

我的问题是:谁能给我这些设备中的每一个的尺寸,或者我可以为每个设备制作一个布局?

图片中的设备爆炸了

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/mainnati"
    android:gravity="center_horizontal" >


>
        <Button

        android:id="@+id/b_info"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_centerVertical="true"
        android:background="@drawable/info" />



    <Button
        android:id="@+id/b_pass"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_alignLeft="@+id/b_comp"
        android:layout_below="@+id/b_comp"
        android:layout_marginTop="350dp"
        android:background="@drawable/pass" />

</RelativeLayout>

【问题讨论】:

  • 发布您的布局文件。
  • 我添加了布局文件,我使用了很多我知道的硬编码!但责任归咎于以这种方式教我的人。我必须尽快完成这个项目。
  • 两件事:我看到两个按钮。第二个在您的代码(b_comp)中不存在的下方并与左侧对齐。所以,我想它应该引用 b_info,而不是
  • “按钮混在一起”到底是什么意思?此外,您谈到了几个(“small, normal, large, xlarge”)布局文件夹,但只显示一个布局 XML。你真的需要 4 种不同的布局吗? (这可能是个坏主意。)首先,试着仔细阅读this

标签: android android-layout android-button


【解决方案1】:

两件事:我看到两个按钮。
第二个在您的代码中不存在的代码 (b_comp) 的下方并与左侧对齐。
所以,我想它应该引用 b_info,而不是。

而且,我会为第一个按钮 (b_info) 设置 centerInParent(它也水平居中),而不是 centerVertical。
我会使用 centerHorizo​​ntal 作为下部按钮,而不是 alignLeft。

所以,毕竟我的布局文件是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/mainnati"
    android:gravity="center_horizontal" >
    >
    <Button
        android:id="@+id/b_info"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_centerInParent="true"
        android:background="@drawable/info" />
    <Button
        android:id="@+id/b_pass"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/b_info"
        android:background="@drawable/pass" />
</RelativeLayout>

【讨论】:

  • 谢谢您,先生,您的编辑对我帮助很大!现在它就像一个魅力,你能解释一下我的工作出了什么问题吗? - 我已经阅读了您之前提供的链接! - 抱歉 (b_comp) 这是一个复制/粘贴错误。 - 我制作了4个布局文件夹以使布局适用于不同的屏幕,因此系统会选择适合当前屏幕的布局。再次感谢。
  • 很高兴它成功了。您需要深入阅读 RelativeLayout 的工作原理。你也不必感到抱歉。发生错误。我还认为您不必制作 4 种不同的布局。只需为按钮的宽度和高度提供“包装内容”。显然,您必须以您想要支持的分辨率(以 dpi 为单位)提供 4 个不同版本的图像。就是这样。
猜你喜欢
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 2011-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-09
相关资源
最近更新 更多