Android Studio中imageButton的图像尺寸应该是多少?

时间:2016-05-07 13:00:59

标签: android android-layout android-studio photoshop

这是图像按钮

this is the button image

图像未显示为imageButton的背景

这是imageButton的截图,将其背景显示为图像

this is screenshot of imageButton after putting it's background as image shown

这是完整的content.xml

    <?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.meggabyte.comppec.MainActivity"
tools:showIn="@layout/activity_main">


<ImageButton
    android:layout_width="300dp"
    android:layout_centerHorizontal="true"
    android:layout_height="wrap_content"
    android:contentDescription="@string/desc"
    android:id="@+id/imageButton"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/ic_action_name"
    android:cropToPadding="false"
    />

enter image description here

2 个答案:

答案 0 :(得分:0)

请改用此代码:

 <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton" android:layout_gravity="center_horizontal" android:src="@drawable/admin"
        android:cropToPadding="false" android:background="null"/>

答案 1 :(得分:0)

您没有将图像分配给ImageView ...您需要XML中的一行说明

android:src="@drawable/some_image"

背景和来源不同