当我按照说明通过xml将广告添加到我的应用中时,出现以下错误:
Description Resource Path Location Type
error: No resource identifier found for attribute 'adSize' in package 'com.google.example' main.xml /HelloWorld/res/layout line 12 Android AAPT Problem
Description Resource Path Location Type
error: No resource identifier found for attribute 'adUnitId' in package 'com.google.example' main.xml /HelloWorld/res/layout line 12 Android AAPT Problem
Run Code Online (Sandbox Code Playgroud)
我编辑了main.xml,添加attrs.xml文件,但编译器不喜欢它.
我试图在我的Android应用程序中使用矢量drawables.来自http://developer.android.com/training/material/drawables.html(强调我的):
在Android 5.0(API Level 21)及更高版本中,您可以定义矢量drawable,它可以在不丢失定义的情况下进行缩放.
使用这个drawable:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="@color/colorPrimary" android:pathData="M14,20A2,2 0 0,1 12,22A2,2 0 0,1 10,20H14M12,2A1,1 0 0,1 13,3V4.08C15.84,4.56 18,7.03 18,10V16L21,19H3L6,16V10C6,7.03 8.16,4.56 11,4.08V3A1,1 0 0,1 12,2Z" />
Run Code Online (Sandbox Code Playgroud)
和这个ImageView:
<ImageView
android:layout_width="400dp"
android:layout_height="400dp"
android:src="@drawable/icon_bell"/>
Run Code Online (Sandbox Code Playgroud)
尝试以400dp显示图标时(在大约2015年左右的移动设备上运行棒棒糖的高分辨率),会产生这种模糊的图像:
将矢量drawable的定义中的宽度和高度更改为200dp可显着改善400dp渲染大小的情况.但是,将此设置为TextView元素的drawable(即文本左侧的图标)现在会创建一个巨大的图标.
我的问题:
1)为什么矢量可绘制中有宽度/高度规格?我认为这些问题的全部意义在于它们无损扩大和缩小,其宽度和高度在其定义中毫无意义?
2)是否可以使用单个矢量drawable,它在TextView上作为24dp可绘制,但可以很好地扩展以使用更大的图像?例如,我如何避免创建不同大小的多个矢量绘图,而是使用一个可以扩展到渲染要求的矢量绘图?
3)如何有效地使用width/height属性以及viewportWidth/Height的区别是什么?
额外细节:
Error:(26) No resource identifier found for attribute 'srcCompat' in package 'learnapp.android.example.com.learnapp'
当我尝试运行我的应用程序时,我得到了.我刚刚开始学习安卓.我添加了一个新活动,并在任何xml文件中更改任何内容.
这是确切的错误:
Documents/MyProjects/LearnApp/app/src/main/res/layout/activity_display_message.xml
Error:(26) No resource identifier found for attribute 'srcCompat' in package 'learnapp.android.example.com.learnapp'
Run Code Online (Sandbox Code Playgroud)
这是我的activity_display_message.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="learnapp.android.example.com.learnapp.DisplayMessageActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_display_message" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我已经阅读过类似的问题,看到了这一行
xmlns:app="http://schemas.android.com/apk/res-auto"
Run Code Online (Sandbox Code Playgroud)
要么
app:srcCompat="@android:drawable/ic_dialog_email" />
Run Code Online (Sandbox Code Playgroud)
在他们的情况下是错误的,这不是我的情况.
重要的是,此活动的父活动是MainActivity.java