【问题标题】:Creating such a Button with Android? (Inspired by iOS)用 Android 创建这样的按钮? (受 iOS 启发)
【发布时间】:2013-01-07 15:29:18
【问题描述】:

在一个 iOS 应用上我看到了这样一个 Button:

我想在 Android 中做同样的事情,我怎么能做到这一点? 我尝试的是以下代码:

<Button
    android:id="@+id/widget41"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:text="Email1 testmail@gmail.com"
    android:textStyle="bold" />

看起来像这样:

嗯,只是一个普通的(丑陋的)按钮。我不知道,我怎么能像在 iOS 中那样设计它。任何建议或链接将不胜感激!

【问题讨论】:

标签: android button styles xamarin.android


【解决方案1】:

最好的解决方案是创建您自己的自定义视图,其行为类似于 iOS 对应视图(不过,正如其他用户所提到的,Android 确实有它自己的设计指南,并且您看到的视图是一个 iOS 实现,它是专为该平台设计)。

如果您查看上面的 iOS 图片(您的副本,其中一些部分突出显示),我已将其拆分为多个部分。

您可以使用像LinearLayout 这样的Android ViewGroup 来创建整体图像,并为LinearLayout 提供边框或背景(例如可以是圆角矩形的位图图像(参见 Android Nine Patch 以获取如何使其适合多个屏幕的示例)。

  1. 首先,对于邮件图标,您需要LeftAligned ImageView 具有适当的尺寸。
  2. 接下来我们有一个Bold TextView,其中包含文本“Email1”。
  3. 这后面是另一个TextView,它是蓝色的,使用 elipsize 属性(在 Android XML 布局中定义)来创建 "..." 在文本达到最大宽度后结束 消耗。 (在 XML 中使用 android:ellipsize="end"
  4. 最后我们有一个指示图像,它也可以是ImageView 大小合适。

您也可以使用RelativeLayout 来实现此目的,这将允许您使用RightAlign 指示图像,LeftAlign 邮件图标,并允许文本填充其可以获取的空间。

九个补丁用于背景的示例here

【讨论】:

    【解决方案2】:

    那是 iOS 中的 UITableView(就像 android 中的 ListView)。这取决于您执行的列表项设计。 Android中没有这样的Button控件。

    【讨论】:

    • Android中没有这样的Button Control吗?真的
    • 你必须像 iOS 一样设计它,但没有直接控制
    【解决方案3】:

    您应该设计自己的按钮,使其看起来像 iOS 按钮。

    Android 有自己的设计指南:

    http://developer.android.com/design/patterns/pure-android.html

    【讨论】:

      【解决方案4】:

      好吧,正如其他人已经明确提到的那样,Android 中没有这样的默认按钮,据您所知,iOS 中也没有。一切都与设计有关。一切皆有可能,最终看你愿意走多远去实现它。

      下面是一个简单的代码,将接近您的设计。

       <TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_centerHorizontal="true"
              android:layout_centerVertical="true"
              android:layout_margin="5dp"
              android:background="@drawable/text_background"
              android:drawableLeft="@drawable/envelope"
              android:drawablePadding="10dp"
              android:drawableRight="@drawable/right_arrow"
              android:ellipsize="end"
              android:gravity="center_vertical"
              android:text="@string/email" />
      

      还可以有其他方式,比如整个视图可以是一个 ViewGroup,一个 LinearLayout 或一个 RelativeLayout,其中可能有多个 TextViews 和 ImageViews。

      【讨论】:

      • 感谢答案,无论如何,我收到错误消息,没有找到 3 @drawables/.. 的资源,另一件事是它应该是一个控件或其他东西,我可以在其中附加点击事件
      【解决方案5】:

      Here 是一个创建风格化 android 按钮的教程。您可以圆角并更改背景颜色,使其看起来像 ios 中的按钮。

      Here 是一个类似的问题。

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-06
        • 1970-01-01
        • 2014-03-12
        • 1970-01-01
        • 2011-10-04
        相关资源
        最近更新 更多