【问题标题】:How to set up custom image buttons for android apps?如何为 Android 应用程序设置自定义图像按钮?
【发布时间】:2016-01-24 08:09:29
【问题描述】:

我在尝试在布局中使用图像按钮时遇到问题。添加第一个图像按钮时一切正常,但是当我添加第二个图像按钮时,第一个会缩小,这是否取决于我使用的布局?我设置了相对布局,但我不知道如何让每个按钮保持相同大小。

<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.supernovastudios.conguate.preguntas3"
android:background="#222222">


<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton5"
    android:background="@drawable/botonpregunta"
    android:layout_centerHorizontal="true" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/botonpregunta"
    android:id="@+id/imageButton6"
    android:layout_alignTop="@+id/imageButton5"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="143dp" />

<ImageButton
    android:layout_width="wrap_content"
    android:background="@drawable/botonpregunta"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton7"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="104dp" />

这是布局的图片。中间的按钮是唯一保持其原始大小的按钮,而其他按钮在我向上或向下移动时似乎会缩小。

【问题讨论】:

  • 可以贴一下xml代码吗?
  • 如果您需要帮助解决问题,请使用您的代码编辑问题!
  • @Sameer 我上传了代码!对不起,我花了这么长时间

标签: android


【解决方案1】:

您在ImageButtons 中使用background 的图像。

您应该在ImageButton 中使用src 的图像

示例:

<ImageButton
    android:id="@+id/imageButton5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitCenter" 
    android:adjustViewBounds="true"
    android:src="@drawable/botonpregunta" />

【讨论】:

  • 我把它当成src,它失去了它的圆形,当我缩小它时它会恢复吗?
  • 显示您的图像。在较大的图像中,角落可能会被切掉。还要检查this。检查更新的答案以及
  • 为什么不添加样式来获得圆角?
猜你喜欢
  • 1970-01-01
  • 2012-12-09
  • 2012-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多