使用 Java 创建二图后,3 个区域会突出显示,并由于某种原因返回警告。我不确定为什么会出现这种情况。可以采取什么措施来消除此警告?
避免在绘制/布局操作期间分配对象(改为预分配和重用)
public class Diagram extends View {
private int measuredWidth, measuredHeight;
private Paint mBackgroundPaint, mYellowLinePaint, mWhiteLinePaint;
private RectF mBackgroundRect, mYellowLineRectF, mWhiteLineRectF;
public Diagram(Context context) {
super(context);
init(context, null, 0);
}
public Diagram(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public Diagram(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
}
private void init(Context context, AttributeSet attributeSet, int defStyle) {
mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBackgroundPaint.setColor(0xFF3C3C3C);
mBackgroundPaint.setStyle(Paint.Style.FILL);
mYellowLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG); …Run Code Online (Sandbox Code Playgroud) 我读过很多关于“如何在 android 中制作响应式应用程序”的文章,每个人都建议为每个屏幕使用“多个位图”。我只是想知道
(1)我们可以考虑支持平板电脑的不同drawable文件夹(drawable-hdpi、drawable-xdpi、drawable-xxdpi等)吗?或者只是这些文件夹是为智能手机设计的以获得响应能力?
我正在尝试使用 Android Commit Content API制作图像键盘。为了实现这一点,我需要能够在设备上存储.png文件.gif并从中创建文件对象。
目前,我正在使用 Glide 库从互联网上获取图像。我可能获取的示例图像是这样的。Glide 库为我提供了drawables包含动画 GIF 的库。我需要能够将这些可绘制对象编码为.gif可以在用户手机上保存为文件的文件。
我怎样才能做到这一点?
我查看了现有的帖子,例如:How to conversion a Drawable to a Bitmap? ,但它们没有帮助,因为该Bitmap对象无法存储动画 GIF。
这篇文章:将 gif 文件从可绘制文件保存到手机 SD 中?并在使用后将其从 SD 中删除似乎也相关,但是,它没有解释如何将动画Drawable对象转换为对象列表Bitmap。
此外,它没有解释如何将一系列Bitmap对象保存为 1 个 GIF 文件。
我想在按钮背景上实现精确的效果,但还没有成功..!有什么帮助吗?
这是图像
到目前为止我的尝试(gradient_bg.xml)
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="@android:color/transparent"
android:startColor="#e3ffffff" />
</shape>
Run Code Online (Sandbox Code Playgroud)
..结果并没有那么多..!
布局
<TextView
fontPath="fonts/Roboto-Regular.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginBottom="-20dp"
android:gravity="start"
android:text="@string/dummy_big"
android:textColor="@color/gray_dark"
android:textSize="13sp"
tools:ignore="MissingPrefix" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/gradient_bg">
<Button
fontPath="fonts/Roboto-Bold.ttf"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginStart="120dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="120dp"
android:layout_marginBottom="20dp"
android:background="@drawable/round_solid_primary"
android:clickable="true"
android:foreground="?selectableItemBackground"
android:gravity="center_vertical|center_horizontal"
android:text="@string/view_more"
android:textColor="@color/ef_white"
android:textSize="15sp"
tools:ignore="MissingPrefix" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud) 我已成功本地化我的 Android 应用程序,但问题是,我正在努力更改选项菜单和底部导航选项卡的本地化语言。无法解决该问题。请帮我。提前致谢)。
android android-drawable android-studio navigation-drawer bottomnavigationview
我无法让BadgeDrawable正常工作。
使用它没有问题BottomNavigationView
navView.setupWithNavController(navController)
val badge = navView.getOrCreateBadge(R.id.navigation_home)
badge.number = 12
Run Code Online (Sandbox Code Playgroud)
但当我想在其他元素上使用它时,它不会显示。像这样:
val badgeDrawable = BadgeDrawable.create(context!!)
badgeDrawable.number = 32
BadgeUtils.attachBadgeDrawable(badgeDrawable, textView, root.findViewById(R.id.frame_layout))
Run Code Online (Sandbox Code Playgroud)
我使用 FrameLayout 只是因为这个问题修复似乎尚未发布。
布局:
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/text_home"
android:src="@drawable/ic_home_black_24dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="20sp" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我正在使用最新的库版本:'com.google.android.material:material:1.2.0-rc01'
我尝试过不同的方法。但运气不好。难道这其中有什么我所遗漏的秘密吗?
这是该项目的 git 存储库(尽可能简单):https ://github.com/marcinkunert/badgeissue
android kotlin android-drawable android-studio material-components-android
编辑:我解决了这个更新UIL库到1.8.0,因为在早期版本中没有从资产文件夹添加图像的功能.我确实错过了.
我正在使用Universal Image Loader库在ListView中显示图像列表
如果图像不存在,我想从drawable或asset文件夹加载占位符.
在库文档上,这是可接受的URI:
String imageUri = "assets://image.png"; // from assets
String imageUri = "drawable://" + R.drawable.image; // from drawables
Run Code Online (Sandbox Code Playgroud)
但使用任一选项都会触发a java.lang.NullPointerException
这是我的onResume方法,我加载我的图像:
@Override
public void onResume() {
super.onResume();
//open connection to db
db = new DBAdapter(this);
db.open();
// get all defects for this unit
defectList = db.getAllDefectsByUnit(unit_id);
// create an array adapter and let it to display our row
defects = new SimpleCursorAdapter(this, R.layout.defect_row, defectList, new String[] { "defect", "image_path" }, new int[] { R.id.defect, …Run Code Online (Sandbox Code Playgroud) 我在drawable概念中有一个查询.我有固定尺寸的图像,我把它们放在可绘制的文件夹中.我从eclipse项目中删除了我的其他文件夹,如drawable-hdpi,mdpi,ldpi,xhdpi,并制作了我的项目的APK.
我的问题是,我的应用程序(生成的apk)将在所有设备和平板电脑上工作(我不关心UI的外观)?或者它可以在某些设备/平板电脑上创建ResourceNotFound Exception,因为不存在所有可绘制的文件夹?
如何创建一个最大圆角的矩形?

我试过了:
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="44dp"
android:height="100dp"/>
<solid android:color="#8c51ff"/>
<corners android:radius="24dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud) 我创建了一个圆角可绘制资源round_corner_bg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dp" android:color="#B1BCBE" />
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
我将它应用于我的LinearLayout:
<LinearLayout ...>
android:background="@drawable/round_corner_bg"
...
Run Code Online (Sandbox Code Playgroud)
它工作正常。但是,它环绕了所有四个角,我怎样才能使它只环绕左上角和右上角?
我正在寻找我的 actionBar 是透明的。我只有 searchView 并且它在我的 MapActivity 中,我只希望 searchView 和“后退”按钮可见。我使用哪个透明度 # 代码填写以下内容:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(parseColor("#")));
Run Code Online (Sandbox Code Playgroud) transparency android background-color color-codes android-drawable
android-drawable ×11
android ×10
java ×2
kotlin ×2
xml ×2
color-codes ×1
gif ×1
gradient ×1
material-components-android ×1
rect ×1
transparency ×1