[英]Scaling drawable resources
I have just done some image editing of my application so now i want to make it fit for every device by scaling them into different sizes. 我刚刚对我的应用程序进行了一些图像编辑,所以现在我希望通过将它们缩放到不同的大小来使其适合每个设备。 I have found a site where i put an image then it scales it to different screen densities so when i put in into my project it does not adapt to the screen.
我找到了一个网站,我放置了一个图像然后它将其缩放到不同的屏幕密度,所以当我进入我的项目时,它不适应屏幕。
Here's the code: 这是代码:
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity"
android:background="@drawable/backgroundapp"
android:orientation="vertical">
<ImageButton
android:id="@+id/btnSwitch"
android:layout_width="105dp"
android:layout_height="105dp"
android:src="@drawable/poweroffline"
android:background="@null"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp" />
<ImageButton
android:id="@+id/FlashBlinkButton"
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/blinkoffline"
android:background="@null"
android:layout_gravity="center_horizontal"
android:layout_below="@+id/btnSwitch"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"/>
<ImageButton
android:layout_width="65dp"
android:layout_height="70dp"
android:id="@+id/AlarmButton"
android:src="@drawable/alarmoffline"
android:background="@null"
android:layout_centerHorizontal="true"
android:layout_below="@id/FlashBlinkButton"
android:layout_marginTop="30dp"/>
</RelativeLayout>
EDIT: It automatically goes for the mdpi folder. 编辑:它自动转到mdpi文件夹。
You can try set android:scaleType 你可以尝试设置android:scaleType
For example : 例如 :
<ImageButton
android:id="@+id/FlashBlinkButton"
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/blinkoffline"
android:background="@null"
android:layout_gravity="center_horizontal"
android:layout_below="@+id/btnSwitch"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:scaleType="fitXY" />
You can see different variations in this docs http://developer.android.com/reference/android/widget/ImageView.ScaleType.html 您可以在此文档中看到不同的变体http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.