标签: android-drawable

创建一个新的颜色drawable

我试图将十六进制值转换为int,以便我可以创建一个新的颜色drawable.我不确定这是否可行,但根据文档,它应该.它显然要求

public ColorDrawable(int color)

在API级别1中添加创建具有指定颜色的新ColorDrawable.

参数 color 要绘制的颜色.

所以,我的代码不起作用,因为我得到一个无效的int:"FF6666"错误.有任何想法吗?

int decode = Integer.decode("FF6666");
ColorDrawable colorDrawable = new ColorDrawable(decode);
Run Code Online (Sandbox Code Playgroud)

java android android-drawable colordrawable

69
推荐指数
4
解决办法
8万
查看次数

缩放图像保持其纵横比在背景中可绘制

如何使背景图像适合视图,但在<bitmap />用作背景可绘制XML 时保持其纵横比?没有<bitmap>android:gravity值给出预期效果的.

scaling android android-drawable android-background android-bitmap

58
推荐指数
3
解决办法
8万
查看次数

如何使用RoundedBitmapDrawable

有人设法使用RoundedBitmapDrawable?如果我错了,请纠正我,但根据我的理解,它会从常规矩形图像中生成圆形图像.

到目前为止我尝试过的是这个

RoundedBitmapDrawable.createRoundedBitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), iconResource))
Run Code Online (Sandbox Code Playgroud)

我试图实现的目标:将任何图像转换为圆形图像并使用ImageView显示它.

如果我把事情搞混了,我所说的都是无意义的.是否可以(或更简单)使用任何新框架?(Android L或新的支持库)

android android-drawable android-bitmap

57
推荐指数
4
解决办法
3万
查看次数

了解Android的<layer-list>

我不明白图层列表是如何工作的.我通过一些例子阅读了官方文档,但它并不像我预期的那样适用于我.我想要四个正方形,应该用1dp填充,但没有任何预期.这是一个按500%缩放的屏幕截图:

我的suares
(错误的颜色无关紧要)
正如您所看到的那样,尺寸完全错误并且缺少填充.我试图设置像宽度/高度和右/左/顶部/按钮的实际值,以确保android得到我想要的点.

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="0dp" android:left="0dp" android:bottom="0dp" android:right="0dp">
        <shape android:shape="rectangle">
            <size android:width="9dp"
                android:height="9dp"/>
            <solid android:color="#f000"/>
        </shape>
    </item>

    <item android:top="1dp" android:left="1dp" android:bottom="5dp" android:right="5dp">
        <shape android:shape="rectangle">
            <size android:width="3dp"
                android:height="3dp"/>
            <solid android:color="#f00"/>
        </shape>
    </item>
    <item android:top="1dp" android:left="5dp" android:bottom="5dp" android:right="1dp">
        <shape android:shape="rectangle">
            <size android:width="3dp"
                android:height="3dp"/>
            <solid android:color="#0f0"/>
        </shape>
    </item>

    <item android:top="5dp" android:left="1dp" android:bottom="1dp" android:right="5dp">
        <shape android:shape="rectangle">
            <size android:width="3dp"
                android:height="3dp"/>
            <solid android:color="#0f0"/>
        </shape>
    </item>
    <item android:top="5dp" android:left="5dp" android:bottom="1dp" android:right="1dp">
        <shape android:shape="rectangle">
            <size android:width="3dp"
                android:height="3dp"/>
            <solid …
Run Code Online (Sandbox Code Playgroud)

android xml-drawable layer-list android-drawable

56
推荐指数
2
解决办法
9万
查看次数

Android Studio:可绘制文件夹:如何为多个dpi放置图像?

,根据Android文档,drawable文件夹需要有不同dpis图像的多个子目录.但是在Android Studio中,在drawable文件夹中创建任何子目录会导致它无法检测到任何图像.另一方面,如果图像直接放在drawable文件夹中,它将被检测到并可用于查看R.drawable.ImageName.在这种情况下,我们如何为同一个ImageName使用不同的dpi图像?

android android-drawable android-studio

56
推荐指数
5
解决办法
12万
查看次数

居中位图标记(Google Maps Android API v2)

当我从自定义位图添加标记时,标记不会在我指定的点居中.

我是这样添加的:

    // ID tramo
    final int tramoId = tr.getId();
    // Nodos
    final Nodo[] nodos = tr.getNodos();

    final PolylineOptions p = new PolylineOptions();
    MarkerOptions m = new MarkerOptions();
    // Seteamos posicion de linea y marker
    m.position(semisuma(nodos));
    for (final Nodo n : nodos) {
        p.add(n.getLatLng());
    }
    // Color de linea y marker
    BitmapDescriptor icon = null;
    if (tr.getCapacidad() == 0) {
        p.color(0xFF000000);
        m = null;
    } else if (tr.getCapacidad() - tr.getPlazasOcupadas() == 0) {
        p.color(0xEEFF0000);
        final TextDrawable drawable = new TextDrawable(0, …
Run Code Online (Sandbox Code Playgroud)

android centering android-drawable google-maps-android-api-2

54
推荐指数
2
解决办法
2万
查看次数

圆角进度条?

我正在努力实现这个进度条设计: 在此输入图像描述

我现有的代码产生了这个: 在此输入图像描述

这是代码:

<item android:id="@android:id/background">
    <shape>
        <corners android:radius="8dp"/>
        <solid android:color="@color/dirtyWhite"/>
    </shape>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners android:radius="8dp"/>
            <solid android:color="@color/colorPrimaryDark"/>
        </shape>
    </clip>
</item>
Run Code Online (Sandbox Code Playgroud)

我的进度条:

 <ProgressBar
            android:id="@+id/activeProgress"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:progress="10"
            android:progressDrawable="@drawable/rounded_corners_progress_bar"/>
Run Code Online (Sandbox Code Playgroud)

我尝试<size><shape>in 上添加属性<clip以使进度形状稍微小一点,但它不起作用.此外,进度条是平的,我想按照设计弯曲.我需要改变才能实现设计?

android android-progressbar android-drawable

50
推荐指数
5
解决办法
2万
查看次数

在ImageView中获取可绘制的ID

我有一个ImageView并设置了一个drawable.现在我需要ImageView动态获取可点击事件的ID .我怎么才能得到它?

imgtopcolor = (ImageView) findViewById(R.id.topcolor); 
imgtopcolor.setImageResource(R.drawable.dr);  // How do I get this back?
Run Code Online (Sandbox Code Playgroud)

现在触摸事件imgtopcolor我想要绘制id因为我每次都设置不同的drawable并且想要将drawable与其他

android android-imageview android-drawable

49
推荐指数
3
解决办法
11万
查看次数

在Android中创建和使用9补丁图像

我最近听说过9张补丁图片.我知道它的9平铺并且是可拉伸的.我想更多地了解它.

  • 如何创建9补丁图像?

    有没有工具?我可以从AndroidSDK或代码创建吗?

  • 9-patch主要优于普通png?

    (它是否可根据屏幕动态/自动伸缩?)

android nine-patch android-drawable

47
推荐指数
4
解决办法
9万
查看次数

如何更改图层列表drawable?

试图学习一些新的东西,无法想出这一点,任何帮助表示赞赏.鉴于这个简单的代码来自Google的文档:

layers.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/first_image">
      <bitmap android:src="@drawable/android_red"
        android:gravity="center" />
    </item>
    <item android:id="@+id/second_image" android:top="10dp" android:left="10dp">
      <bitmap android:src="@drawable/android_green"
        android:gravity="center" />
    </item>
    <item android:id="@+id/third_image" android:top="20dp" android:left="20dp">
      <bitmap android:src="@drawable/android_blue"
        android:gravity="center" />
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

和main.xml:

<ImageView
    android:id="@+myImageView"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/layers" />
Run Code Online (Sandbox Code Playgroud)

问题:如何以编程方式引用图层列表中的一个drawable,以便将其更改为不同的drawable?

谢谢.

所以现在我有了我的新drawable,我想换变量myImage正确吗?现在我如何将其纳入图层列表?我想我用findDrawableByLayerIdsetDrawableByLayerId,但究竟如何?或者我可能完全错了!救命!

我想做什么?更改显示的drawable.例如,假设我有另一个名为"android_purple"的drawable,我将如何在上面的layer-list示例中为"android_green"drawable切换它?

编辑:

随着我在这里有限的知识是到目前为止我的代码(它工作,我得到的错误setDrawableByLayerId是不确定的):

Resources res = getApplicationContext().getResources();
BitmapDrawable newImage = (BitmapDrawable) res.getDrawable(R.drawable.android_purple); //Get replacement image, can't use LayerDrawable or get error.   
boolean layer_drawable_changed = (setDrawableByLayerId((R.id.second_image), newImage)); //Set …
Run Code Online (Sandbox Code Playgroud)

android android-drawable

43
推荐指数
2
解决办法
5万
查看次数