我有一个字典对象:
menu = {'dinner':{'chicken':'good','beef':'average','vegetarian':{'tofu':'good','salad':{'caeser':'bad','italian':'average'}},'pork':'bad'}}
Run Code Online (Sandbox Code Playgroud)
我试图使用pydot与"菜单"数据创建一个图表(决策树)此.
'晚餐'将是顶级节点,其价值(鸡肉,牛肉等)低于它.参考链接,图形函数有两个参数; 源和节点.
它看起来像这样:
"王"将是"晚餐","主"将是"鸡肉","牛肉"等.
我的问题是:如何访问值中的键?要从这些数据创建一个树,我觉得我需要创建一个循环,检查是否有特定键的值并绘制它.我不确定如何调用任何字典对象的值(如果它不一定被称为'晚餐'或具有尽可能多的元素.).
有关如何绘制图表的任何建议吗?
我正在创建一个像这样的ImageButton:
<ImageButton
android:id="@+id/one"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.333"
android:adjustViewBounds="true"
android:background="@null"
android:contentDescription="@string/description_image_button_one"
android:scaleType="fitEnd"
android:src="@drawable/dialpad_1" />
Run Code Online (Sandbox Code Playgroud)
我想实现一种方法,让按钮闪烁或点击/按下时改变颜色只是为了识别它被点击了.我知道我可以将背景引用为一个drawable,其中state_pressed选择器为某种颜色.我试图避免为drawable中的每个按钮创建一个单独的xml文件.如果不创建所有额外的xml文件,最好的方法是什么?
我正在创建一个RecyclerView
带标题,当你向上滚动时标题会崩溃RecyclerView
.我可以通过下面的布局非常密切地实现这一点,透明AppBarLayout
,MyCoolView
这是标题.视差效果很好.
但是,如果标题仍然可见并且我扔了RecyclerView
,则RV缓慢滚动到顶部,一些项目在工具栏下,直到RV到达视图的顶部.我一直在玩,scrollFlags
但没有取得理想的结果.有关如何改善投掷体验的任何建议,以免物品被剪裁?
观看视频,观看视频时的精彩内容--- https://www.dropbox.com/s/jppd6m7zo41k23z/20160609_151309.mp4?dl=0
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout
android:background="#00000000">
<android.support.design.widget.CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<com.android.myapp.MyCoolView
app:layout_collapseMode="parallax"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-support-library android-design-library android-coordinatorlayout android-appbarlayout
我想替换字符串句子中的单词,例如:
What $noun$ is $verb$?
Run Code Online (Sandbox Code Playgroud)
使用实际名词/动词替换"$ $"(包括)中的字符的正则表达式是什么?
我正在通过onActivityResult
相机传递一个位图.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "picture");
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(intent, REQUEST_TAKE_PHOTO);
Run Code Online (Sandbox Code Playgroud)
我可以得到位图:
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mCapturedImageURI);
Run Code Online (Sandbox Code Playgroud)
但是,我注意到图像在某些设备上旋转.在这里搜索帖子后,典型的解决方案似乎通过以下方式获得轮换:
String path = mCapturedImageURI.getPath();
ExifInterface exif = new ExifInterface(path);
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
Run Code Online (Sandbox Code Playgroud)
不幸的是,int rotation
即使位图旋转,我总是0.
我也试过这个,当我在设备上已经上传了一张图片但方向仍为0时有效:
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = managedQuery(mCapturedImageURI, orientationColumn, null, null, null);
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Run Code Online (Sandbox Code Playgroud)
有人看到我在这里做错了吗?还是另一种解决方法?
通常,位图与后置摄像头逆时针旋转90度,前置摄像头顺时针旋转90度.在Moto G上运行正常.在Galaxy S3和LG G2上旋转.
将 BillingClient 升级到 3.0.0 后,我开始让大约 20% 的用户SERVICE_UNAVAILABLE
在查询应用内购买时看到。skuDetailsList 也是空的。根据该文件,SERVICE_UNAVAILABLE
意味着网络出现故障,但如何在客户端返回OK
与startConnection
和试图查询SKU信息后发送此邮件?此外,我看到了一些ERROR
,即代码 6。我是否有一些不正确的实现,还是只是向用户显示了一些“发生错误。稍后再试”消息?我也没有在 Play 管理中心或任何可能导致这种情况的国家/地区看到任何警告。
BillingClient billingClient = BillingClient.newBuilder(getContext())
.enablePendingPurchases()
.setListener((billingResult, list) -> {})
.build();
mBillingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
createSkus(mBillingClient);
}
}
@Override
public void onBillingServiceDisconnected() {}
});
private void createSkus(BillingClient billingClient) {
List<String> skuList = new ArrayList<>();
skuList.add("pro");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
billingClient.querySkuDetailsAsync(params.build(),
(billingResult, skuDetailsList) -> {
// skuDetailsList empty with …
Run Code Online (Sandbox Code Playgroud) I'm implementing a zoomable View from examples I've found on Stack and other websites. I do want to add a drawing feature to the view. I'm able to get the paths to show up but the scaling is way off from the image behind it. I used an example android image where I traced along the shape and the paths appeared to the left and above it. Also, zooming causes it to shift (pictures below).
I've been playing around with …
我有一个Result.objects.all()
大约15个对象的数据库.结果有一个名为score的字段,范围从1-5.所以如果我预先形成q = Result.objecets.get(id=1)
,那么q.score
2.什么是找到所有15个对象的所有分数的平均值的方法?
我正在寻找一种通过onClick更改Button中文本颜色的方法.我想要更改所选按钮文本颜色,并希望其他按钮的文本恢复为默认颜色.这种方式(下面)似乎非常低效.还有更好的方法吗?另外,如何使用onClick恢复原始颜色?
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
TextView textView1 = (TextView) findViewById(R.id.button1);
textView1.setTextColor(Color.RED);
logLevel = "E";
//Change the rest to default (white)
break;
case R.id.button2:
TextView textView2 = (TextView) findViewById(R.id.button2);
textView2.setTextColor(Color.RED);
logLevel = "W";
//Change the rest to white
break;
case R.id.button3:
TextView textView3 = (TextView) findViewById(R.id.button3);
textView3.setTextColor(Color.RED);
logLevel = "D";
//Change the rest to white
break;
case R.id.button4:
TextView textView4 = (TextView) findViewById(R.id.button4);
textView4.setTextColor(Color.RED);
logLevel = "I";
//Change the rest to white
break;
}
retrieveLog(logLevel);
}
Run Code Online (Sandbox Code Playgroud) 从我的库中选择图像时,我无法获得方向.如果我转到图像细节,我可以看到图像方向设置为90度.但是,我的方向始终为0.
String[] orientationColumn = { MediaStore.Images.ImageColumns.ORIENTATION };
Cursor cur = managedQuery(data.getData(), orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Run Code Online (Sandbox Code Playgroud)
使用ExitInterface:
ExifInterface exif = new ExifInterface(data.getData().getPath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION);
Run Code Online (Sandbox Code Playgroud)
两种方式都返回0.我从库启动select活动,如下所示:
protected void selectFromLibrary() {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent,
REQUEST_SELECT_IMAGE_FILE);
}
Run Code Online (Sandbox Code Playgroud)
这是在运行4.4.2的LG G2上