How to add XML drawable in Eclipse

后端 未结 8 602
青春惊慌失措
青春惊慌失措 2021-01-02 22:21

Ok guys I\'m little stacked here. According to official documentation Google says that \"Once you\'ve defined your Drawable in XML, save the file in the res/drawable/ direct

相关标签:
8条回答
  • 2021-01-02 23:00

    Just create a drawable folder by yourself and put your files there.

    0 讨论(0)
  • 2021-01-02 23:05

    I have that problem sometimes.

    I always create the XML drawable as "New text file". If you get an error after the XML drawable has been created, check the XML syntax to be sure there is no error in the file, and try to clean the project (Project->Clean->Your project)

    Good luck

    0 讨论(0)
  • 2021-01-02 23:12

    As of today, there is no "direct" support to drawable resources in Eclipse ADT.

    So, from Eclipse Package Explorer, you should "manually" add a new folder named 'drawable' into your project 'res' folder.

    Then, still from Package Explorer, you should manually add a new XML file within the newly created folder (right click\ new\ other\ XML\ XML File).

    0 讨论(0)
  • 2021-01-02 23:12

    Why cant you use BitmapDrawable heres a sample code:

    <?xml version="1.0" encoding="utf-8"?>
    <bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/drawable_resource"
    android:gravity="center"
    android:tileMode="repeat"/>
    
    1. Just replace with your drawable src name and save this as .xml file.
    2. Store the file in res/drawable directory.
    3. Assign the reference to android:background="@drawable/drawable_resource" and it will be tiled.

    Example:

    <LinearLayout
    android:background="@drawable/drawable_resource"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    </LineatLayout
    

    Heres a complete template of Bitmap Drawable, you can choose attribute values accourding to your need.

    <?xml version="1.0" encoding="utf-8"?>
    <bitmap
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@[package:]drawable/drawable_resource"
        android:antialias=["true" | "false"]
        android:dither=["true" | "false"]
        android:filter=["true" | "false"]
        android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
                          "fill_vertical" | "center_horizontal" | "fill_horizontal" |
                          "center" | "fill" | "clip_vertical" | "clip_horizontal"]
        android:tileMode=["disabled" | "clamp" | "repeat" | "mirror"] />
    

    You can find documentation of the same here look for XML Bitmap.

    0 讨论(0)
  • 2021-01-02 23:13

    Drag and drop an image-button from "Images&Media" folder in palette. When the dialog for choosing an icon is shown, klick on "create a new icon" down below, enter a name for your new drawable (only small letters) and then choose your image and what the drawable is for (a button or what so ever). Remember to choose the right THEME, that you are creating the icon for (a light theme or a dark theme). Eclipse will resize the pic and do all the rest work for you to have good-looking drawable. After that, you can delete the image-button. It's a kind of strange, but it works that way the fastest and WITHOUT CODING and without any graphical working or any filemanagement!!!!

    0 讨论(0)
  • 2021-01-02 23:17

    This worked for me in creating a "drawable" folder inside the res folder. Right click on the res folder->New->Other->General->Folder then Next

    Select res from the set of folders under your project then

    give it the "drawable" name and Finish!

    0 讨论(0)
提交回复
热议问题