【问题标题】:How to create Android UI mimicking the Living Social UI?如何创建模仿 Living Social UI 的 Android UI?
【发布时间】:2015-06-22 09:19:01
【问题描述】:

我对 Android UI 设计相当陌生。我正在尝试模仿以下 Living Social 屏幕截图的 UI 设计:

在这里构建 UI 元素的最佳方式是什么?这如何在 XML 中实现?我正在尝试使用 Android Eclipse UI 编辑器来拖放 UI 元素,但似乎我需要对 UI 进行动态编程。解决此类问题的推荐方法是什么?

到目前为止,我有以下内容:

<LinearLayout 
    android:id="@+id/LinearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin">

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" 
            >
            <ImageView
                android:id="@+id/imageViewBackground"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_gravity="fill"
                android:scaleType="fitXY"
                android:src="@android:drawable/dialog_holo_dark_frame" />
            <View
                android:id="@+id/view1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <View
                android:id="@+id/view2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <View
                android:id="@+id/view3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:backgroundTint="@color/abc_search_url_text_normal"
        android:gravity="bottom|end"
        android:orientation="vertical" >

        <Button
            android:id="@+id/buttonBUY"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="BUY!" />
    </LinearLayout>
</LinearLayout>

问题:

  1. 我正在使用父线性布局。在这里面,我有一个顶部的 ScrollView 和底部的 LinearLayout。底部的 LinearLayout 有一个 BUY NOW 按钮的子按钮。这是正确的父布局方案吗?
  2. ScrollView 内部是一个 ImageView,它与 ScrollView 的顶部对齐。然后,滚动视图内部是 X 个白框。如何将内部白框视图稍微放在 ImageView 的顶部?我需要以编程方式执行此操作吗?
  3. 推荐的创建内部白盒视图的方法是什么?我是否需要为每个文件创建一个单独的 .xml 视图文件?或者您会建议为每个白框使用一个片段吗?或者,我是否需要为每个白框实现自定义视图类?

谢谢

【问题讨论】:

  • 您要做的第一件事是尝试使用 Android Studio,它为布局开发提供了非常好的选择,而不是 eclipse 提供的。
  • 谢谢哈雷什。我将尝试 Android Studio。对于滚动视图中的白框,我应该如何处理?我应该创建一个片段、自定义视图,还是简单地为它们每个创建单独的 .xml 文件并使用 LayoutInflator 类?
  • 另外,您知道与此示例类似的任何好的教程或示例应用程序吗?
  • 使用支持实时布局编辑器的 Android Studio!
  • 我认为你的白框可能看起来像卡片布局,所以必须在这里查看:developer.android.com/training/material/…

标签: android android-layout android-fragments android-view


【解决方案1】:

您可能需要在线性布局控件中使用视差效果和CardView controls。为了添加底部按钮,您可以使用相对布局。至于视差,请看下面的帖子:How to do the new PlayStore parallax effect

【讨论】:

  • 感谢@Access Denied 的回答。在 LivingSocial 应用程序中,背景图像实际上是固定的,第一个白框位于其顶部。我似乎找不到正确的布局层次顺序来实现这一点。你推荐一个父RelativeLayout。然后在其中,按钮的 ScrollView + LinearLayout。那么在ScrollView里面,里面应该是什么呢?我应该为每个白盒创建一个 .xml 还是为每个白盒创建片段/自定义视图?谢谢
  • 这个任务不需要使用片段。片段在主细节案例和需要切换不同 UI 共享一个模型时很好。简而言之,视图层次结构如下: ...
  • 非常感谢!现在我明白了,正如你所建议的那样,什么时候使用片段很好。最后一个问题 - 什么时候应该使用 .xml 预制视图而不是编程自定义视图?
  • 其实这两种变体都不错。您可以组合来自代码的视图或使用 xml。 xml 更简单,而且它使您有机会拥有不同的布局,例如垂直方向和水平方向,而无需付出很多努力。在这种情况下,您还可以将设计与代码分开。此外,您还有 xml 设计器,无需启动您的应用程序即可查看它的外观。至于继承的视图,如果您需要扩展控制行为并重用它,则值得使用。
猜你喜欢
  • 1970-01-01
  • 2011-06-23
  • 2021-02-08
  • 2011-01-08
  • 1970-01-01
  • 2020-01-29
  • 2017-05-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多