android - 缩放 XML 中的可绘制资源 (Android)

标签 android xml android-layout

我正在尝试将可绘制对象缩放到其原始大小的两倍。我正在尝试使用它:Drawable Resouces .我当前的代码是:

可绘制:

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/ic_launcher"
    android:scaleHeight="80%"
    android:scaleWidth="80%" >

</scale>

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/scale2" />

</LinearLayout>

但是第二个 ImageView 中没有显示任何内容。我该如何解决?

最佳答案

一旦我遇到这个问题,我就通过使用插图而不是比例尺找到了解决方案。 在 drawable 文件夹中创建一个新的 xml drawable 文件并添加如下代码:

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/buttonright"
android:insetTop="4dp"
android:insetLeft="4dp"
android:insetRight="4dp"
android:insetBottom="4dp"
/>

这样使用

   <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/scale" />

关于android - 缩放 XML 中的可绘制资源 (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14195206/

相关文章:

android - 提供者和条件的 requestLocationUpdates

java - 在 android 应用程序项目的 adt 20 中添加外部 jar

java - Android Studio setSupportActionBar 不起作用

Java 如何使用 JAXB 注释在 XML 中添加子元素

xml - 'Android' 中的所见即所得 View 编辑器?

android - 第一次点击图片没有反应,需要再次点击,为什么?

javascript - 在 Cordova Android 浏览器中打开 URL

java - Android facebook 哈希键错误 - 'c:\Program' 未被识别为内部或外部命令,

java - 将图像添加到 GridView 时 AsyncTask 崩溃

Android Studio : Rendering Problems Missing styles-correct theme chosen for this layout, 无法找到带有 id 的样式