【问题标题】:Does Android support this kind of button which can press left and rightAndroid是否支持这种可以左右按的按钮
【发布时间】:2014-01-09 12:50:38
【问题描述】:

Android 是否支持上述这种按钮?

按键为小键盘,如果按右,里面的文字会向右移动并切换到下一个选择,否则按左,文字会向左移动...

对这种按钮有什么想法吗?

谢谢!

【问题讨论】:

  • 您可以制作此按钮的三个版本。 1. 像, 2. 点击右侧的样子, 3. 点击左侧的样子。然后你使用 imageview 来显示图像并自己处理点击
  • 查看我的答案,我已经发布了完整解决的布局

标签: android button customization


【解决方案1】:

您好,请使用android提供的切换按钮

http://developer.android.com/guide/topics/ui/controls/togglebutton.html

【讨论】:

    【解决方案2】:

    您不能根据按下的区域使按钮动作不同。但您可以设计“水平”线性布局。

    -创建 2 个图像视图(1 个用于左侧,1 个用于右侧)
    - 将这 2 个控件放置在 LinearLayout 内(水平方向)
    - 为每一个设置不同的 onClick 处理函数

    【讨论】:

      【解决方案3】:

      使用 relativelayout 试试这个::

      <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"
      android:id="@+id/rlt1"   
      tools:context=".MainActivity" >
      
      <RelativeLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@drawable/bg" >
      
          <ImageButton
              android:id="@+id/leftArrowId"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_alignParentTop="true"
              android:layout_marginLeft="24dp"
              android:src="@drawable/larrow" />
      
          <ImageButton
              android:id="@+id/rightArrowId"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:layout_alignParentTop="true"
              android:layout_marginRight="24dp"
              android:src="@drawable/rarrow" />
      
      </RelativeLayout>
      

      根据您的图像取两个不同的箭头图标,一个左一个右和一个背景图像

      背景图片bg将是

      左箭头将是

      右箭头将是

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-14
        • 1970-01-01
        • 1970-01-01
        • 2017-01-29
        • 1970-01-01
        • 2014-11-06
        • 1970-01-01
        相关资源
        最近更新 更多