【问题标题】:How to build this layout in Android? [closed]如何在 Android 中构建这种布局? [关闭]
【发布时间】:2014-09-13 15:28:04
【问题描述】:

我是 Android 新手,我设法完成了我的应用程序。我应该将 iOS 应用程序转换为 Android 应用程序,因此开发了 WS。我即将完成应用程序,但还有两个问题。我无法为最后两个制作相同的布局。前两个图像是 iOS,最后一个是 Android。我不了解 iOS 的 AutoLayout 之类的 RelativeLayout 的规则,我如何使主页在每个屏幕上看起来都很棒(也就是说,每个按钮的大小都合适并且组织良好)。目前,我设法使前 3 个 imageButtons 没问题,但是在更大的屏幕上,这些按钮的大小不完全适合屏幕,怎么会?

提前非常感谢!

imageHomeiOS http://img15.hostingpics.net/pics/781886CapturedcranduSimulateuriOS3juil2014210948.png imageProfileiOS http://img15.hostingpics.net/pics/583953CapturedcranduSimulateuriOS3juil2014211025.png imageHomeAnd http://img15.hostingpics.net/pics/695608Capturedcran20140722190415.png imageProfileAnd http://img15.hostingpics.net/pics/313733Capturedcran20140722190428.png

【问题讨论】:

  • 从您的问题来看,我猜您正在尝试查看以特定分辨率开发的屏幕,而设备具有不同的分辨率?如果是这样,您的视图布局文件必须设置为所有必需的分辨率。

标签: android ios eclipse layout screen


【解决方案1】:

我不确定棉绒的性能:嵌套重量不利于性能。 不过试试吧,我觉得7个按键不会影响性能。

<?xml version="1.0" encoding="utf-8"?>

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon"
            android:adjustViewBounds="true" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon"
            android:adjustViewBounds="true" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon"
            android:adjustViewBounds="true" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon"
            android:adjustViewBounds="true" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon"
            android:adjustViewBounds="true" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon"
            android:adjustViewBounds="true" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <View
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon"
            android:adjustViewBounds="true" />

        <View
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent" />
    </LinearLayout>


</LinearLayout>

【讨论】:

  • 哇,这真是太完美了!非常感谢 !对于碰巧遇到此问题的其他人,请在每个 imageButton 中添加 android:scaleType="centerInside" 以便正确缩放您的图像!完美的 !非常感谢,我会自己找到其他布局!
【解决方案2】:

尝试使用加权布局而不是相对布局。您可以将水平线性布局定义为 weightSum = 3,然后给每个按钮一个 layout_weight = 1。权重总和将基本上将屏幕分成许多部分,无论屏幕大小如何,并给出每个部分的一部分到你赋予权重的元素。确保在定义各个元素的 layout_width 时,将其定义为 0dp。元素的宽度将不再由 layout_width 标签设置,而是由其占用的权重设置。

【讨论】:

    猜你喜欢
    • 2020-10-23
    • 1970-01-01
    • 2021-07-26
    • 2015-09-14
    • 2013-09-09
    • 1970-01-01
    • 2017-04-15
    相关资源
    最近更新 更多