{"id":17182199,"url":"https://github.com/wuseal/textwithimagedrawable","last_synced_at":"2025-03-17T11:30:27.702Z","repository":{"id":93273753,"uuid":"62545892","full_name":"wuseal/TextWithImageDrawable","owner":"wuseal","description":"图文混排的drawable    An android drawable object which contains text and image and even complex drawable ","archived":false,"fork":false,"pushed_at":"2017-09-21T04:49:59.000Z","size":151,"stargazers_count":129,"open_issues_count":2,"forks_count":33,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T23:02:33.848Z","etag":null,"topics":["android-drawables","complex-drawable","mixdrawable","textdrawable","textimage","textimageview"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wuseal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-07-04T08:40:29.000Z","updated_at":"2023-06-24T19:36:27.000Z","dependencies_parsed_at":"2023-03-06T20:15:30.418Z","dependency_job_id":null,"html_url":"https://github.com/wuseal/TextWithImageDrawable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuseal%2FTextWithImageDrawable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuseal%2FTextWithImageDrawable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuseal%2FTextWithImageDrawable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuseal%2FTextWithImageDrawable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wuseal","download_url":"https://codeload.github.com/wuseal/TextWithImageDrawable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243858056,"owners_count":20359271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-drawables","complex-drawable","mixdrawable","textdrawable","textimage","textimageview"],"created_at":"2024-10-15T00:36:18.875Z","updated_at":"2025-03-17T11:30:27.188Z","avatar_url":"https://github.com/wuseal.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TextWithImageDrawable\nAn android drawable object which contains text and image\n\n可以同时包含文字和图像的Drawable,也可以单独只包含文字或是图像\n\n##使用步骤\n* 在app的构建文件build.gradle中的dependencies中加入下面的代码\n\n ```groove\n \n   compile 'wu.seal:textwithimagedrawable:1.0.4'\n \n ```\n\n* 然后就可以直接在代码中使用就可以了\n\n## Api的简单介绍\n\n```java\n\n            /**\n             * 实例化一个同时包含文字和图片的drawable\n             */\n            TextWithImageDrawable textWithImageDrawable = new TextWithImageDrawable(thisActivity);\n            /**\n             * 设置drawable里的文字\n             */\n            textWithImageDrawable.setText(text);\n            /**\n             * 设置drawable里的图像资源\n             */\n            textWithImageDrawable.setImageRes(leftMenuIconResId);\n             /**\n             * 设置drawable里的图像资源\n             */\n            textWithImageDrawable.setImageBitmap(mBitmap);\n             /**\n             * 设置drawable里的drawable\n             */\n            textWithImageDrawable.setDrawable(mDrawable);\n            /**\n             * 设置drawable中文字的大小,注意此处的单位是sp\n             */\n            textWithImageDrawable.setTextSize(16);\n            /**\n             * 设置文字的颜色\n             */\n            textWithImageDrawable.setTextColor(getResources().getColor(R.color.text_color_white));\n            /**\n             * 设置文字和图像之间的间隔,单位是px\n             */\n            textWithImageDrawable.setImagePadding(DensityUtils.dip2px(5));\n            /**\n             * 设置此drawable的左边填充大小,单位px\n             */\n            textWithImageDrawable.setPaddingLeft(DensityUtils.dip2px(8));\n            /**\n             * 设置此drawable上方填充大小,单位px\n             */\n            textWithImageDrawable.setPaddingTop(DensityUtils.dip2px(6));\n            /**\n             * 设置此drawable的最大文字限制长度\n             */\n            textWithImageDrawable.setMaxTextLength(3);\n            /**\n             * 设置图像和文字的相对位置,此处设置的是图像在文字右边显示\n             */\n            textWithImageDrawable.setImagePosition(TextWithImageDrawable.Position.RIGHT);\n\n```\n## 使用示例:\n\n```java\n\n    ImageView left, right, top, bottom;\n\n    String mText = \"text\";\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        /**\n         *  图像资源显示在文字左边的显示效果\n         */\n        left = (ImageView) findViewById(R.id.iv_left);\n        /**\n         *  图像资源显示在文字右边的显示效果\n         */\n        right = (ImageView) findViewById(R.id.iv_right);\n        /**\n         *  图像资源显示在文字上边的显示效果\n         */\n        top = (ImageView) findViewById(R.id.iv_top);\n        /**\n         *  图像资源显示在文字下边的显示效果\n         */\n        bottom = (ImageView) findViewById(R.id.iv_bottom);\n\n        /**\n         * 图像和文字之间的距离\n         */\n        final int drawablePadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics());\n\n        TextWithImageDrawable drawableLeft = new TextWithImageDrawable(this);\n        initDrawable(drawablePadding, drawableLeft, mText, TextWithImageDrawable.Position.LEFT);\n        left.setImageDrawable(drawableLeft);\n\n        TextWithImageDrawable drawableRight = new TextWithImageDrawable(this);\n        initDrawable(drawablePadding, drawableRight, mText, TextWithImageDrawable.Position.RIGHT);\n        right.setImageDrawable(drawableRight);\n\n        TextWithImageDrawable drawableTop = new TextWithImageDrawable(this);\n        initDrawable(drawablePadding, drawableTop, mText, TextWithImageDrawable.Position.TOP);\n        top.setImageDrawable(drawableTop);\n\n        TextWithImageDrawable drawableBottom = new TextWithImageDrawable(this);\n        initDrawable(drawablePadding, drawableBottom, mText, TextWithImageDrawable.Position.BOTTOM);\n        bottom.setImageDrawable(drawableBottom);\n\n\n\n\n    }\n\n    private void initDrawable(int drawablePadding, TextWithImageDrawable drawable, String mText, TextWithImageDrawable.Position position) {\n        drawable.setText(mText);\n        drawable.setImagePosition(position);\n        drawable.setImagePadding(drawablePadding);\n        drawable.setImageRes(R.mipmap.ic_launcher);\n    }\n\n```\n\n# BaseCombinedDrawable\nAn android drawable object which contains two drawables\n\n一个组合drawable,能对两个drawable进行拼凑组合成一个新的drawable,两个drawable的位置可以灵活组合,基本能满足所有的drawable的定制,各种图文混排,你懂的\n\n##Api介绍\n\n```java\n\n     /**\n     * 设置drawable two 左上角相对于 drawable one左上角 的相对偏移位置\n     * 偏移以drawable one 的左上角为起始点\n     * drawable one 会优先放在最前面进行绘制(如果两个drawable的相对偏移值为0则效果如同FrameLayout)\n     *\n     * @param relatedX x轴的相对偏移\n     * @param relatedY y轴的相对偏移值\n     */\n     public void setRelatedPosition(int relatedX, int relatedY)\n    \n    \n    /**\n     * 设置组合后的新的drawable的四个Padding值\n     *\n     * @param paddingLeft   左边填充距离\n     * @param paddingTop    上边填充距离\n     * @param paddingRight  右边填充距离\n     * @param paddingBottom 下边填充距离\n     */\n     public void setPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom)\n    \n```\n\n##代码示例\n\n```java\n\n        BaseCombinedDrawable baseCombinedDrawable = new BaseCombinedDrawable(drawableLeft, drawableRight);\n        baseCombinedDrawable.setRelatedPosition(drawableLeft.getIntrinsicWidth() + drawablePadding, 0);\n        combine.setImageDrawable(baseCombinedDrawable);\n\n```\n\n\n##效果图:\n\u003cimg src=\"https://github.com/wuseal/TextWithImageDrawable/blob/master/demo.png?raw=true\" alt=\"alt text\" \u003e\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwuseal%2Ftextwithimagedrawable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwuseal%2Ftextwithimagedrawable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwuseal%2Ftextwithimagedrawable/lists"}