2017-04-25 59 views
-1

我已经创建了带有图标的文本按钮。但我的图标更大。我怎样才能为每个分辨率创建不同的图像大小?在Android中调整图标+文本按钮的大小

注:我使用的是Android 2.2.3工作室

这里是我的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" 
tools:context="com.example.asus.teacher.TeacherActivity"> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/ic_eye" 
    android:text="Drawable left" 
    android:textSize="10dp" 
    /> 
</RelativeLayout> 

回答

0

我怎样才能为每个分辨率

有创建不同的图像大小有几种方法:

  1. 使用Android Asset Studio

  2. 也有第三方库,将不同的文件夹中生成图像像hdpi , xhdpi , mdpi等可以使用Drawable Resizer

  3. 还有一个在线工具用于这一目的。像This

FOR XML:您可以设置高度,宽度,填充,保证金,重力等。

<Button 
    android:id="@+id/button1" 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:padding="4dp" 
    android:drawableLeft="@drawable/ic_eye" 
    android:text="Drawable left" 
    android:textSize="10sp" 
    /> 
+0

他们很酷,但我不知道是否有任何其他方式来调整XML文件中的图像的大小? –

+0

我编辑了答案...如果图标很大,您可以将特定尺寸高度设置为包装图标的按钮...... – rafsanahmad007

0

您可以调整使用iconify

你也可以用你的ImageButton图标并设置“adjustViewBound”属性true,这样你只需要修复宽度和高度就可以根据比例进行调整。