我正在开发Android应用程序,应该支持2.1直到最新的Android OS(4.2)版本.目前我的图像库模块中只显示少量图像.我需要在所有支持操作系统的设备(智能手机和平板电脑)上支持我的应用程序,范围从2.1到4.2(最新).
每张图像大小分别为368X387,每张50 KB,PNG类型
我的工作区res包含以下可绘制文件夹:
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-xdpi
Run Code Online (Sandbox Code Playgroud)
我有些困惑
我应该在哪个文件夹中存储图像,这有什么关系?
我是否需要为不同类型的设备提供不同的基于分辨率的图像?
谢谢.
这就是我提出的.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/grey" />
<padding
android:bottom="1dp" />
<corners
android:radius="0dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/white" />
<corners
android:radius="1dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
这是有效的,但是底部半径显示我放在它上面的任何值.
实际上只需要topLeftRadius让它看起来像这样
<corners
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="0dp"/>
Run Code Online (Sandbox Code Playgroud)

使用Kitkat但也尝试使用jellybean并且我无法获得自定义错误图标.
我从Android doc使用这两个重载方法来设置setError(...)
我只是做了非常简单的代码:
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class MainActivity extends Activity implements OnCheckedChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.report_issue);
RadioGroup rg = (RadioGroup) findViewById(R.id.myradio_group);
rg.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.radio_two) {
EditText et = (EditText) findViewById(R.id.et_city);
// rb.setError("i got a single error");
et.setError("my error",
getResources().getDrawable(R.drawable.ic_launcher));
//as you can see from above im setting …Run Code Online (Sandbox Code Playgroud) 我想画一个矩形。第一个角应该是用户首先触摸屏幕的位置。用户移动手指时,应绘制矩形。这是一个显示视频的链接,我想做什么。但是我不明白,也许您可以帮助我。我只想在白色背景上而不是图像上绘制该矩形。
我的代码:
package com.example.androiddrawing;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class CanvasView extends View {
private Canvas canvas;
private Paint paint = new Paint();
private Paint paint2 = new Paint();
private Paint paint3 = new Paint();
private Path path = new Path();
private Point point = new Point();
private static List<Path> lines = new ArrayList<Path>();
private static List<Point> points …Run Code Online (Sandbox Code Playgroud) private void changePicture(int stageIndex){
try{
iv=(ImageView) findViewById(R.id.imageView2);
Picture picture=new Picture();
String v =picture.getPicFileName();
InputStream ims = getAssets().open(v);
Drawable d = Drawable.createFromStream(ims, null);
iv.setImageDrawable(d);
}catch(IOException ex){
return;
}
}
Run Code Online (Sandbox Code Playgroud)
我想从/asset文件夹中加载图像列表,所以我编写了此函数,但是它不起作用。有人能帮我吗?
我正在尝试在我的RecyclerView中使用以下代码使用可绘制着色
Drawable likeDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.ic_thumb_up);
Drawable likeWrappedDrawable = DrawableCompat.wrap(likeDrawable);
DrawableCompat.setTint(likeWrappedDrawable,ContextCompat.getColor(getActivity(), android.R.color.white));
holder.ivLike.setImageDrawable(likeWrappedDrawable);
Run Code Online (Sandbox Code Playgroud)
现在,所有这些工作都在onBindViewHolderRecyclerView Adapter的中完成。
我会根据该列表项的状态在三种颜色之间更改此色调。对于Lolipop及更高版本,这一切正常,但在此版本以下,列表项目的颜色是无法预测的。有时它显示正确的颜色,但刷新列表时有时会更改为其他颜色。
Anything im doing wrong here or the tinting thing on pre-lollipop is still unusable in this particular case?
Update
Including the code from my onBindViewHolder
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
...
Drawable likeDrawable =
ContextCompat.getDrawable(getActivity(), R.drawable.ic_thumb_up);
Drawable likeWrappedDrawable = DrawableCompat.wrap(likeDrawable);
holder.tvLikeCount.setTextColor(ResUtil.getColor(R.color.light_font,
getActivity()));
DrawableCompat.setTint(likeWrappedDrawable,
ContextCompat.getColor(getActivity(), android.R.color.white));
if (tweetModel.isFavorited()) {
DrawableCompat.setTint(likeWrappedDrawable,
ContextCompat.getColor(getActivity(), android.R.color.holo_blue_light));
}
holder.ivLike.setImageDrawable(likeWrappedDrawable);
}
Run Code Online (Sandbox Code Playgroud) 我在可绘制的png中有一个图标。黑色,透明背景。如何在不添加其他可绘制对象的情况下更改图标颜色?
在日常开发中,很多时候需要检查drawable文件夹中的图标,并且许多图标具有相似的名称,因此很难识别要使用的图标.我每次都要打开图标,双击它来检查它.
所以我的问题是:有没有办法直接在可绘制列表中显示图标而不打开它?附加屏幕截图以获得更好的可见性.
我有FAB并试图将drawable(round_drawable.xml)填充到整个晶圆厂,但是drawable当前显示在左上角,如下所示,
我尝试了从设置src和FloatingActionButton的背景的解决方案, 但是它不起作用,从其他来源添加了大多数属性,但是都scaleType, src, background不起作用。
我如何用round_drawable填充FAB?
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="100dp"
android:layout_height="95dp"
android:scaleType="fitXY"
app:backgroundTint="@color/white"
android:src="@drawable/round_drawable"
android:backgroundTintMode="src_atop"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
round_drawable.xml
@drawable/right 是向右箭头的png图片。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:innerRadius="50dp"
android:shape="oval">
<corners android:radius="10dp" />
<gradient
android:angle="45"
android:endColor="#D425B5"
android:startColor="#EBF928" />
</shape>
</item>
<item
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp">
<bitmap
android:gravity="center"
android:src="@drawable/right" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)