我知道在C++中0x
或者NULL
被nullptr
基于指针的应用程序所取代.我只是好奇他们为什么要更换它?
在处理指针时,在什么情况下使用nullptr
过度NULL
有益?
我正在编写一个编程项目,我需要做的一件事就是写一个函数,它返回一个掩码,标记最低有效位的位.关于如何使用按位运算符确定位置的任何想法?
ex:
0000 0000 0000 0000 0000 0000 0110 0000 = 96
What can I do with the # 96 to turn it into:
0000 0000 0000 0000 0000 0000 0010 0000 = 32
Run Code Online (Sandbox Code Playgroud)
我一直在靠墙砸了好几个小时试图解决这个问题,任何帮助都会非常感激!
所以我得到一个错误的布局膨胀,关于NoSuchMethodException.我已经看过其他解决方案了,我已经确定我已经完成了以下操作,我已经完成了这个例外.有谁知道这可能导致什么?我完全迷失了,一切正常,然后我更新了我的android工作室,现在我收到了这个错误.
我的活动是AppCompatActivity
我的应用布局,使用AppCompat:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的布局代码,使用app命名空间设置背景色调:
<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"
android:src="@drawable/ic_add_white_18dp"
app:backgroundTint="@color/colorPrimary"
app:layout_behavior="Behaviors.ScrollAwareFABBehavior"/>
<include layout="@layout/content_main" />
Run Code Online (Sandbox Code Playgroud)
这是我的gradle构建文件:
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.google.android.gms:play-services:9.4.0'
Run Code Online (Sandbox Code Playgroud)
这是我的堆栈跟踪:
java.lang.NoSuchMethodError: android.support.v7.widget.AppCompatImageHelper.<init>(Landroid/widget/ImageView;Landroid/support/v7/widget/AppCompatDrawableManager;)V
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:133)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:110)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为FileInputStream
用户从他们的图库中选择的图片获取一个对象,当我尝试从我收到的URI中打开文件时,它一直在说FileNotFoundException
......
这是我用来启动从图库中选择图像的意图的代码:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
Run Code Online (Sandbox Code Playgroud)
这是我用来捕捉的代码onActivityResult
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
File myFile = new File(uri.getPath());
FileInputStream fiStream = new FileInputStream(myFile);
...
}
}
Run Code Online (Sandbox Code Playgroud)
在创建的时候FileInputStream
,我通过模拟器选择了一张照片时出现了以下错误:
W/System.err: java.io.FileNotFoundException: /document/image:26171: open failed: ENOENT (No such file or …
Run Code Online (Sandbox Code Playgroud) 我正在 GDB 中运行一些汇编代码试图调试我的程序,我想看看如果我完全忽略一条指令会发生什么,有没有办法做到这一点?(跳过它到下一行而不执行它)而不必编辑源代码并注释掉函数然后重新编译?
我正在另一个线程中运行一个函数,该线程应该填写一个对话框然后显示它,但是只要我尝试以任何方式更改该对话框,它就会出现段错误。我已经读到这是WxPython的常见问题,并且开发人员无意直接更改另一个线程中的对话框。
我该如何解决?我可以在主线程中调用该函数,但这会阻塞我的GUI,并且初始化对话框是一项冗长的操作-我想避免这种情况。
我的代码类似于以下内容。
# Create the dialog and initialize it
thread.start_new_thread(self.init_dialog, (arg, arg, arg...))
Run Code Online (Sandbox Code Playgroud)
def init_dialog(self, arg, arg, arg....):
dialog = MyFrame(self, "Dialog")
# Setup the dialog
# ....
dialog.Show()
Run Code Online (Sandbox Code Playgroud)
即使对话框为空,而只是在函数内部显示一个简单的调用,我仍会遇到分段错误。任何帮助将不胜感激,谢谢。
因此,我在上传的用户上方设置了带有白色文本标签的透明按钮ImageView
。如果用户上传的图像大部分是白色的,则按钮很难看清,即使不是完全看不见。
有谁知道获取ImageView
原始图片/可绘制对象的平均颜色的方法吗?如果可以,可以将其与某个阈值进行比较,可以尝试...如果可以,则可以将按钮上文本的颜色更改为该颜色的反色。 。或者其他的东西??
只是在这里随地吐痰..
当然,如果有人知道更好的方法,将不胜感激更多信息,谢谢!!
user-interface android imageview android-layout color-detection
我已经实现了下面的代码来缩小图像的纵横比(通过相对于彼此成比例地减小高度/宽度)。这肯定有助于减小上传到我后端的图像的大小,但这并没有考虑到图像的分辨率。我想设置一个硬图像限制,比如 800Kb,如果图像在调整大小后大于 800Kb,则压缩到小于 800Kb 的点。
任何人都有做这样的事情的经验?我很好奇传递给 Bitmap.Compress 方法的质量参数与每个质量百分比减少的文件大小之间有什么关系 - 如果我能获得这些信息,我相信我可以达到我的目标。
提前感谢您的任何帮助,我当前的代码如下,也许它会帮助其他人在未来朝着这个方向前进。
public static void uploadImage(String url, File file, Callback callback, Context context,
IMAGE_PURPOSE purpose) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
int maxWidth = 0;
int maxHeight = 0;
int maxSize = 0;
switch(purpose){
case PROFILE:
maxWidth = Constants.MAX_PROFILE_IMAGE_WIDTH;
maxHeight = Constants.MAX_PROFILE_IMAGE_HEIGHT;
maxSize = Constants.MAX_PROFILE_IMAGE_SIZE;
break;
case UPLOAD:
maxWidth = Constants.MAX_UPLOAD_IMAGE_WIDTH;
maxHeight = Constants.MAX_UPLOAD_IMAGE_HEIGHT;
maxSize = Constants.MAX_UPLOAD_IMAGE_SIZE;
break;
}
int newWidth = bitmap.getWidth(); …
Run Code Online (Sandbox Code Playgroud) 所以我试图在我的主要导航栏下方的标签栏和布局处理我的主要活动.
我似乎无法获得ViewPager/TabLayout(不确定问题的原因,这是新的)加载正确的片段.我已经阅读了大量的文档,并检查了超过1个教程,看看我是否正确地做了这个,似乎我正在做同样的事情......
在OnTabSelectedListener
我的TabLayout
正确看到标签的变化,并在OnTabSelected
林打电话viewPager.setCurrentItem(tab.getPosition())
,试图把我viewpagers项目,但它仍然没有工作.首次加载时,它会加载第一个和第二个选项卡(我可以通过片段onCreate方法发送的API请求看到),当我点击其他选项卡时,它会一直加载错误的片段,有时甚至根本不加载一个!
不确定这是否相关但我在切换标签时收到此警告:
03-03 16:24:22.940 16967-16967/com.sampleapp.app W/FragmentManager: moveToState: Fragment state for BlankFragment3{efddbec #2 id=0x7f0c007b android:switcher:2131492987:2} not updated inline; expected state 3 found 2
我正在使用构建工具版本23.0.2
和以下依赖项:
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
Run Code Online (Sandbox Code Playgroud)
这是我的主导航栏的布局代码:
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<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/toolbar1"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud) android android-layout android-fragments android-viewpager android-tablayout
所以为了达到这一点,我已经遵循了这个教程:http: //blog.grafixartist.com/parallax-scrolling-tabs-design-support-library/
在本教程中,使用了一个使用RecyclerView给出片段的viewpager.我正在尝试使用包含LinearLayout的Scrollview来提供ViewPager片段.
我的ViewPager和TabLayouts工作正常.问题是,我不认为CollapsingToolbarLayout正在捕捉ScrollViews的滚动行为.我可以通过向上滚动来折叠工具栏,我可以在我的滚动视图中滚动,但是动作没有被链接,因为它们应该是 - CoordinatorLayout不应该照顾这个吗?也许这是设置不正确?如果有人发现了什么,请告诉我 - 提前谢谢!!
这是我正在使用的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/htab_maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/htab_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/htab_collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<ImageView
android:id="@+id/htab_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mountains"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/htab_toolbar"
android:layout_width="match_parent"
android:layout_height="104dp"
android:gravity="top"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleMarginTop="13dp" />
<android.support.design.widget.TabLayout
android:id="@+id/htab_tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:tabIndicatorColor="@android:color/white" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_object_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
这里是我设置ViewPager的片段(两个标签都是用于测试的相同片段的实例):
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".objectDetailsFragment"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.LinearLayoutCompat …
Run Code Online (Sandbox Code Playgroud) android android-layout material-design android-collapsingtoolbarlayout
我试图找出如何创建,例如,一个看起来像这样的字典:d[keys[0]][keys[1]][keys[2]]
从这样的列表:keys = ["key1", "key2", "key3"]
...
我尝试过以下方法:
keys = ["key1", "key2", "key3"]
d = {}
d_ref= d
for key_num, key in enumerate(keys):
if key_num < len(keys)-1:
d[key] = {}
d_ref = d[key]
else:
d_ref[key] = []
print(d)
Run Code Online (Sandbox Code Playgroud)
但结果如下:
{'key1': {}, 'key2': {'key3': []}}
我的目标是这个输出:
{'key1' : { 'key2' : { "key3" : [] } } }
感谢wim的回答让我得到了我想要的结果:
keys = ["key1", "key2", "key3"]
d = []
for key in reversed(keys):
d = {key: d}
print(d)
Run Code Online (Sandbox Code Playgroud)