我正在寻找方法在我的应用中减少我称之为"id污染"的方法.据我所知,R.id
对于应用程序来说是全局的,所以在每个Activity中我通常都会为元素创建唯一的资源id值,即使我有很多相同的东西.例如,如果我有三个Activity类,每个类都有一个save和cancel按钮,我会为它定义六个唯一的id R.id
:
R.id.actOne_save
R.id.actOne_cancel
R.id.actTwo_save
R.id.actTwo_cancel
R.id.actThree_save
R.id.actThree_cancel
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎没用,因为我真的只需要在任何Activity上运行两个.在生成资源ID时,您都使用了哪些实践?你是否在活动之间重复使用它们?如果一个id同时存在于两个Activites(可能是一个暂停和一个前景)上,那还可以吗?我害怕奇怪的行为,比如按钮点击太多的听众!
我正在从设计角度寻找一些想法,我希望Romain或谷歌的其中一个人也会接受这个想法.您对ListView元素的设计做了什么,使用户明白哪些元素是交互式的,哪些不是?
在iPhone UI中,这是包含披露指示箭头的地方,但将该想法复制/粘贴到Android应用程序中感觉不对.当我们包含节标题时,它们通常在视觉上足够不同(不同的大小和背景)来说明这一点,但是在只有一些列表元素导致更多信息的情况下呢?
我很欣赏有关此主题的所有想法,并希望看到Android UI指南中涵盖的更多内容.
对于那些在Android源代码中花费了大量时间的人来说,在android.R
类中生成的ID 不是1:1反映res/
在提供的JAR 的目录中找到的实际资源并不是新闻.许多drawables/styles/layouts不是"公共的",并且可以通过引用访问应用程序android.R.xxx
.
我的问题是,是否有人知道Android
能够生成与实际资源图不同的R.java类的机制?其次,它是一种机制(使用构建规则等),我们作为开发人员可以利用它来部分保护在用作库的应用程序中公开的ID吗?
提前致谢!
有没有使用当前的命令行工具(一种方式adb
,am
,pm
)来模拟用户从设置应用压力停止?kill <pid>
从shell 调用只能模拟系统杀死进程时发生的事情,但Force Stop通过删除ActivityRecord
Android保存的实例来删除应用程序的内存.
我们可以调用shell命令来模拟这种相同的行为吗?
干杯.
我需要在iPhone上创建一个水平滚动图像库的视图.问题是这个库有可能有100到1000个需要呈现的图像,所以我想避免一次将它们全部加载到一个UIScrollView中并破坏性能.我需要创建一个视图来循环视图对象(如UITableView)以提高性能并减少内存开销,但它需要以水平方式滚动.
有任何想法吗?是否可以水平进行UITableView操作?
谢谢!
我的应用中有以下代码可供访问PeripheralManagerService
:
PeripheralManagerService service = new PeripheralManagerService();
Gpio ledGpio;
try {
ledGpio = service.openGpio("BCM6");
ledGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
} catch (IOException e) {
Log.e(TAG, "Error configuring GPIO pins", e);
}
Run Code Online (Sandbox Code Playgroud)
更新到最新的Android Things(开发人员预览版7)后,我的应用程序现在正在抛出NoClassDefFoundError
:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManagerService;
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.things.pio.PeripheralManagerService" on path: DexPathList[...]
Run Code Online (Sandbox Code Playgroud)
此代码之前正在运行,为什么在更新后这种情况开始发生?
遵循Edge TPU开发板入门上的说明时,我无法走过步骤2:
$ screen /dev/ttyUSB0 115200
Run Code Online (Sandbox Code Playgroud)
问题是屏幕立即返回
[screen is terminating]
Run Code Online (Sandbox Code Playgroud)
我已经验证了/etc/udev/rules.d/65-edgetpu-board.rules的内容,验证了dmesg输出,尝试了不同的USB端口,验证了所有屏幕实例均已关闭,等等。
我正在寻找布局系统的一些见解.是否有人知道Android布局系统中允许对等 View
元素(意味着在同一容器中组合在一起的视图)匹配其高度和宽度属性而不创建插页式容器以控制其大小的方法?
例如:布局有两个TextView
元素.第一个应该始终将宽度包装到其文本内容,但第二个应该匹配第一个的宽度.WORKS的解决方案是这样的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但是,我必须为两个视图创建一个特殊的容器,以确保它们都匹配第一个文本的宽度; 为层次结构添加不必要的复杂性 我想知道的是,如果有一个布局属性我可以用来做这样的事情:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textTwo"
android:layout_widthMatchPeer="@id/textOne" <!-- An attribute like this -->
android:layout_height="wrap_content"
android:layout_below="@id/textOne" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
创建一个硬尺寸作为宽度会破坏让主要元素包裹的目的.有没有人知道的技术,或者我错过的属性,才能实现这一目标?可以在任何标准布局中,我只是选择RelativeLayout
作为一个例子.
另外,如果元素不在彼此附近怎么办?
干杯.
我有一个应用Service
程序使用该Messenger
接口与远程进程通信.以下是设置方式的基本架构:
Handler
包装Messenger
Service
Messenger
成Intent
并调用startService()
以将消息传递给远程服务Intent
,然后通过发送Message
给该Messenger
操作来返回响应.以下是操作中的基本代码:
public class SessionOperation {
/* ... */
public void runOperation() {
Intent serviceIntent = new Intent(SERVICE_ACTION);
/* Add some other extras specific to each operation */
serviceIntent.putExtra(Intent.EXTRA_EMAIL, replyMessenger);
context.startService(serviceIntent);
}
private Handler mAckHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
//Process the service's response
}
};
protected Messenger replyMessenger = new …
Run Code Online (Sandbox Code Playgroud) android ×6
resources ×2
adb ×1
google-coral ×1
iphone ×1
layout ×1
listview ×1
match ×1
memory-leaks ×1
r.java-file ×1
service ×1
shell ×1
tpu ×1
uiscrollview ×1
uitableview ×1