本文介绍了如何更改按钮上的 drawableLeft 图标大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 4 个按钮上添加了一些图标,它们在按钮旁边看起来很大.那么我该如何调整它们的大小呢?我在按钮上使用了 drawableLeft 来添加图标.
I added some icons on 4 buttons and they look so big next to the button. So how can I resize them? I used drawableLeft on the buttons to add icons.
可绘制对象称为交易、奖杯、拼图和扩音器.图标太大了.content_main.xml 文件:
The drawables are called deal, trophy, puzzle and megaphone. The icons are too big.The content_main.xml file:
<?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:id="@+id/content_main"
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="tr.k12.evrim.evrimnews.MainActivity"
tools:showIn="@layout/activity_main">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/frameLayout"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Giriş Yap"
android:onClick="SignIn"
android:textStyle="bold"
style="@style/Widget.AppCompat.Button.Colored"/>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_below="@id/frameLayout"
android:orientation="vertical">
<Button
android:text="Duyurular"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_below="@+id/frameLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:id="@+id/button2"
android:drawableLeft="@drawable/megaphone" />
<Button
android:text="Kadromuz"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_below="@+id/button2"
android:layout_alignEnd="@+id/button2"
android:layout_marginTop="13dp"
android:id="@+id/button3"
android:drawableLeft="@drawable/puzzle"/>
<Button
android:text="Başarılarımız"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="12dp"
android:id="@+id/button5"
android:drawableLeft="@drawable/trophy"/>
<Button
android:text="Ortaklarımız"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="12dp"
android:id="@+id/button4"
android:drawableLeft="@drawable/deal"/>
</LinearLayout>
</RelativeLayout>
推荐答案
将您的资源包装在一个可定义您所需大小的可绘制对象中,类似于:
Wrap your resource in a drawable that defines your desired size similar to:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/icon"
android:width="@dimen/icon_size"
android:height="@dimen/icon_size"
/>
</layer-list >
之后,在你的 android:drawableLeft
标签中使用这个 drawable
After that, use this drawable in your android:drawableLeft
tag
这篇关于如何更改按钮上的 drawableLeft 图标大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!