目前我正在学习用于Android开发的OpenGL ES.现在我在这里我要处理点ModelMatrix和CameraMatrix,但我有它的一些问题:在OpenGL中我们总是用4x4矩阵,我理解为什么我们这样做,但我不知道在哪里不同的值存储在这个矩阵.例如旋转和位置.假设我们有这个4x4矩阵:
0 1 2 3
-----------------
0 | | | | |
-----------------
1 | | | | |
-----------------
2 | | | | |
-----------------
3 | | | | |
-----------------
Run Code Online (Sandbox Code Playgroud)
你能告诉我在哪里可以找到当前的rotation,position以及scale这个矩阵中的物体/相机吗?这是针对同一位置的每个矩阵吗?
我从这样的BroadcastReceiver启动一个服务
Intent service = new Intent(context, MyService.class);
context.startService(service);
String s = "Hello World";
MyService.addString(s);
Run Code Online (Sandbox Code Playgroud)
addString是一个静态函数,它将String添加到ListView.现在我遇到的问题是,在MyService onCreate()运行且未初始化ListView时调用此函数.我该怎么做才能等到onCreate方法完成?
在我的应用程序中,我有一个BroadcastReceiver看起来像这样的东西:
public class MyBroadcastReceiver extends BroadcastReceiver
{
public static final String CUSTOM_BROADCAST_1 = "com.cilenco.application1";
public static final String CUSTOM_BROADCAST_2 = "com.cilenco.application2";
private boolean lastState = false;
@Override
public void onReceive(Context context, Intent intent)
{
final String action = intent.getAction();
boolean cb1 = CUSTOM_BROADCAST_1.equals(action);
boolean cb2 = CUSTOM_BROADCAST_2.equals(action);
if(cb1) lastState = true;
else if(cb2) lastState = false;
Toast.makeText(context, "" + lastState, Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,每次收到广播时,变量lastState都是假的.我确信该onReceive方法被正确调用.你有什么想法吗?对我来说,看起来BroadcastReceiver每次收到广播时都会重新初始化.这是正确的,如果是,我怎么能避免这个问题?我BroadcastReceiver在清单中注册如下:
<receiver
android:name="service.MyBroadcastReceiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="com.cilenco.application1"/> …Run Code Online (Sandbox Code Playgroud) 目前我正在使用汇编语言.我想打印一个字符到控制台,我的程序运行没有错误,但它没有输出.这是我目前的代码:
movl $4, %eax #Defines Output
movl $1, %ebx #STDOUT as first parameter
movl $48, %ecx #Copy char (0) to ECX
movl $1, %edx #String length 1
int $0x80 #Trigger Interrupt
movl %eax, %ebx #Exitcode 0
movl $1, %eax #System Code SYS_EXIT
int $0x80 #Trigger Interrupt
Run Code Online (Sandbox Code Playgroud)
你有什么想法,为什么它没有输出?如您所见,我正在使用GAS语法.我的代码有什么问题?
目前我开始学习Kotlin。我有一个这样的财产:
var startTime: Int
get() = {
// read value from database
}
set(value) {
// save value to database
}
Run Code Online (Sandbox Code Playgroud)
在这里,每次使用 getter 和 setter 时,我总是读取和写入该值。
这个属性可以被惰性评估吗?我想在第一次使用 getter 时读取该值并将其缓存以供后续调用。我知道值可能是惰性的,但我没有发现任何关于变量的信息。Kotlin 中缓存此属性的正确方法是什么?
我可以使用以下代码将列表写入文件:
MyList<Integer> l = new MyList<Integer>();
//...
FileOutputStream fos = new FileOutputStream(filename);
ObjectOutputStream writer = new ObjectOutputStream(fos);
writer.writeObject(l);
writer.close();
Run Code Online (Sandbox Code Playgroud)
现在我想从文件中读取列表,并尝试使用此代码:
MyList<Integer> list = new MyList<Integer>();
//...
FileInputStream fis = new FileInputStream(filename);
ObjectInputStream reader = new ObjectInputStream(fis);
list = (MyList<Integer>) reader.readObject();
reader.close();
Run Code Online (Sandbox Code Playgroud)
但是现在我SuppressWarnings unchecked从Eclipse 获得了一个,我必须检查ClassNotFoundException.为什么这样,我该如何防止这种情况?
在我的 Android 应用程序中,我有一个PreferenceFragment从 XML 资源文件构建的。加载 XML 后,我想为PreferenceFragment 中的每个调用一个方法。我的问题是我还没有找到一种方法可以为我提供当前的所有首选项PreferenceFragment.
我知道我可以通过该findPreference(...)方法找到一个首选项,但我想获得所有首选项的迭代器。错过了方法还是我们无法获得所有首选项?
我相对来说是C++的新手,这可能是一个愚蠢的问题,但我现在正试图理解rValue和lValue引用这一点,我想到了:
假设我们有一个地图(来自数据库或其他),我们想要将它的所有值复制到矢量.
void insertItems(std::vector<std::string>& v)
{
std::map<int, std::string> names = loadFromDb();
for (auto& kv : names )
{
v.push_back(std::move(kv.second));
}
}
Run Code Online (Sandbox Code Playgroud)
std::move在这里使用是对的吗?std::string提供了一个移动构造函数(可能不是用于字符串,但对于较大的对象),移动构造函数比复制构造函数快得多.我们也知道我们不会在其他地方使用地图的项目,一旦我们离开该功能它们就会超出范围.我的推定是对的吗?
我不能在我的思想中看到矛盾,但这是一个复杂的话题,我害怕错过一些东西. PS:我认为问题名称不是最好的.如果你有一个更好的人随时编辑它.
在我的应用程序中,我有以下布局,它使用其内部的新圆形定位属性ConstraintLayout。我认为它非常好,因为除了circleRadius.
这正是我的问题:我的circleRadius也应该是动态的,但根据文档,它只需要维度。所以我需要的是一个相对于constraintCircle大小的维度。那可能吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content"
tools:context="com.cilenco.ui.activities.OnboardingActivity"
tools:theme="@style/AppTheme.Onboarding">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_above="@id/dividor" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:paddingStart="@dimen/spacing_normal"
android:paddingEnd="@dimen/spacing_normal"
android:layout_above="@id/dividor">
<ImageView
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
android:adjustViewBounds="true"
android:contentDescription="@string/empty"
android:cropToPadding="true"
android:paddingLeft="72dp"
android:paddingRight="72dp"
android:paddingBottom="72dp"
android:paddingTop="60dp"
android:tint="@color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="visible"/>
<ImageView
android:id="@+id/icon_left"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.20"
android:contentDescription="@string/empty"
android:adjustViewBounds="true"
android:padding="@dimen/spacing_normal"
app:layout_constraintCircle="@id/icon"
app:layout_constraintCircleRadius="160dp"
app:layout_constraintCircleAngle="250" />
<ImageView
android:id="@+id/icon_bottom_left"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.20"
android:contentDescription="@string/empty"
android:adjustViewBounds="true"
android:padding="@dimen/spacing_normal" …Run Code Online (Sandbox Code Playgroud) 我目前正在使用新的 Jetpack compose UI 工具包,我非常喜欢它。我无法弄清楚的一件事是如何stickyHeaders在LazyColumn由分页库填充的a中使用。文档中的非分页示例是:
val grouped = contacts.groupBy { it.firstName[0] }
fun ContactsList(grouped: Map<Char, List<Contact>>) {
LazyColumn {
grouped.forEach { (initial, contactsForInitial) ->
stickyHeader {
CharacterHeader(initial)
}
items(contactsForInitial) { contact ->
ContactListItem(contact)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
由于我使用的是分页库,groupedBy因此我无法使用它,因此我尝试使用该insertSeparators函数PagingData并像这样自己插入/创建标头(请忽略遗留Date代码,它仅用于测试):
// On my flow
.insertSeparators { before, after ->
when {
before == null -> ListItem.HeaderItem(after?.workout?.time ?: 0)
after == null -> ListItem.HeaderItem(before.workout.time)
(Date(before.workout.time).day != Date(after.workout.time).day) ->
ListItem.HeaderItem(before.workout.time) …Run Code Online (Sandbox Code Playgroud)