<?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/com.org.BatteryManager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<com.org.BatteryManager.BatteryView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:textColor="#ffffffff"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
什么是 com.org.BatteryManager.BatteryView?
如果您想使用自定义视图,那么这是可能的。实现方法是在 Java 中创建一个自定义视图类,该类扩展了一些基本视图组件类。
例如,我在许多应用程序中使用自定义图库组件。gallery 类只会在滑动时向左或向右移动一帧,这与默认行为不同。
我制作自定义图库的方法是扩展基本的 Gallery 类——
package com.testing.whatever;
public class CustomGallery extends Gallery {
//CODE OVERRIDES HERE
}
Run Code Online (Sandbox Code Playgroud)
然后在我的 XML 代码中,该代码看起来与您已有的代码类似 --
<com.testing.whatever.CustomGallery android:layout_width="fill_parent" android:layout_height="fill_parent" />
Run Code Online (Sandbox Code Playgroud)
我怀疑您收到错误是因为您没有编码 com.org.BatteryManager.BatteryView 或者它位于 java 文件中的错误位置。