Android 如何使图像适合我的按钮
每次我在我的按钮中添加和图像(希望将其添加到文本下方)时,它只显示图像的左上方,并将其自身添加到按钮的顶部,即使在我使用android:drawableBottom时也是如此 以下是我的XML代码:Android 如何使图像适合我的按钮,android,android-layout,android-activity,android-button,Android,Android Layout,Android Activity,Android Button,每次我在我的按钮中添加和图像(希望将其添加到文本下方)时,它只显示图像的左上方,并将其自身添加到按钮的顶部,即使在我使用android:drawableBottom时也是如此 以下是我的XML代码: <Button android:layout_width="162dp" android:layout_height="200dp" android:text="@string/weather_station" android:textStyle="bold"
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="@string/weather_station"
android:textStyle="bold"
android:textSize="18dp"
android:background="@drawable/weather"
android:paddingBottom="120dp"
android:paddingLeft="5dp"
android:typeface="monospace"
android:id="@+id/weather_station" />
android:drawableBottom="@drawable/weatherman"
/>
android:drawableBottom=“@drawable/weatherman”
/>
怎么可能连你的画线都不在scop里?尝试上面的工作代码使用
图像按钮
而不是使用按钮
,并尝试缩放图像`
<ImageButton
android:id="@+id/my_image_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="@drawable/my_img" />
尝试在xml中为“填充图像”按钮设置“下比例”类型
android:scaleType="scaleXY"
因此,将此属性放入xml代码中
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="@string/weather_station"
android:textStyle="bold"
android:textSize="18dp"
android:background="@drawable/weather"
android:paddingBottom="120dp"
android:scaleType="scaleXY"
android:paddingLeft="5dp"
android:typeface="monospace"
android:id="@+id/weather_station"
android:drawableBottom="@drawable/weatherman"/>
为什么不将ImageView和TextView作为子视图使用视图组(如垂直线性布局)而不是按钮,然后将onClickListener设置为视图组?使用TextView而不是按钮,然后可以设置可绘制底部我使用了按钮,它对其中一个起作用,然后我尝试了另一个,但仍然有相同的错误。实际上,我在页面上制作了4个按钮,实际上它在范围内,这只是因为我粘贴时没有可绘制的线条,而是自己在stackoveflow上写的。
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="@string/weather_station"
android:textStyle="bold"
android:textSize="18dp"
android:background="@drawable/weather"
android:paddingBottom="120dp"
android:scaleType="scaleXY"
android:paddingLeft="5dp"
android:typeface="monospace"
android:id="@+id/weather_station"
android:drawableBottom="@drawable/weatherman"/>