我曾经给Android Views提供简单的ID,但最近由于这个问题,我完全停止了该操作。
Let's say I have 2 layouts, one named first_layout.xml and second named second_layout.xml. In each of these layouts, there is a view with id username_input. This id is used in different activity classes to access target view, be it ButterKnife binding, Kotlin Android Extensions, or even findViewById.
Now, for whatever reason, I need to rename id in just one layout. Thus I do Refactor -> Rename. What happens? Android Studio simply replaces id …
我尝试使用CameraX api为我的应用内相机实现广角选项,但遇到了一个问题 -CameraControl.setZoomRatio允许在ZoomState.getMinZoomRatio()和之间设置变焦ZoomState.getMaxZoomRatio(),在我测试的手机上minZoomRatio是1.0f。同一款手机支持缩小到0.5f系统相机内。
当前片段我如何初始化相机:
private var camera: Camera? = null
private var imageCapture: ImageCapture? = null
private fun startCamera() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener({
val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
val preview = Preview.Builder()
.build()
.also {
it.setSurfaceProvider(binding.viewFinder.surfaceProvider)
}
imageCapture = ImageCapture.Builder()
.setFlashMode(ImageCapture.FLASH_MODE_AUTO)
.build()
val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
try {
cameraProvider.unbindAll()
camera = cameraProvider.bindToLifecycle(
this, cameraSelector, preview, imageCapture
)
viewModel.onCameraStarted()
} catch (exc: Exception) {
Timber.e(exc)
}
}, …Run Code Online (Sandbox Code Playgroud) 考虑这个例子:
#include <iostream>
#include <type_traits>
template <class, class = void>
struct is_defined : std::false_type
{ };
template <class T>
struct is_defined<T,
std::enable_if_t<std::is_object<T>::value &&
!std::is_pointer<T>::value
>
> : std::true_type
{
private:
static const T test; //try to create incomplete type member
};
struct defined { };
struct forward_declared;
int main()
{
std::cout << std::boolalpha
<< is_defined<defined>::value << std::endl
<< is_defined<forward_declared>::value << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
输出是true两者兼而有之.我想如果我尝试创建struct不完整类型的成员,那么这个模板特化将从重载集中丢弃.但事实并非如此.删除static const原因不完整类型的编译时错误.这种方法有什么问题,如果有可能,怎么能实现呢?
我正在搞乱新的位置,并制作了这段代码:
#include <iostream>
#include <functional>
#include <new>
int main()
{
char memory[sizeof(int)]; //memory to hold type
auto ref = std::ref(*new (memory) int{5}); //allocating int in memory, and make a reference to it
std::cout << ref << std::endl;
new (memory) unsigned{6}; //"overwrite"
std::cout << ref << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
5那么输出6,但它是否定义明确?如果是这样,如果我用作float第二种类型可以吗?
与我一起工作的平面设计师提供了全屏闪屏图像。我被要求以某种方式使用它,它的工作方式就像将ImageViewscaleType 设置为centerCrop. 我还被要求在应用程序启动时立即显示此图像。
因此,我尝试通过windowBackground属性设置应用程序启动画面,但它被拉伸,就好像 scaletype 是fitXY(在ImageView术语中)。互联网上的人们都使用它,或者使用应用程序图标居中且背景设置为特定颜色的可绘制资源,如本文所述:https : //android.jlelse.eu/the-complete-android-splash-screen-guide- c7db82bce565
所以我的问题是 - 是否可以centerCrop在使用时实现行为windowBackground,所以它的工作原理如下:
(原始提供的左侧全屏图像。黑色边框表示设备分辨率)
注意我不能将活动布局用于启动画面。
由于 java/kotlin 中不允许多重继承,因此利用接口默认方法很有用。给出的例子:
abstract class Animal {
fun beAnimal() {
println("I'm animal!")
}
}
abstract class Mammal : Animal() {
fun produceMilk() {
beAnimal().apply { println("Freesh milk!") }
}
}
abstract class AnimalWithBeak : Animal() {
fun quack() {
beAnimal().apply { println("Quack!") }
}
}
class Platypus : ??? // I want it to both produce milk and quack!
Run Code Online (Sandbox Code Playgroud)
如上所述,不允许使用多个基类,但我们可以使用接口:
abstract class Animal { fun beAnimal() { println("I'm animal!") } }
interface Mammal {
fun produceMilk() {
(this as Animal).beAnimal().apply …Run Code Online (Sandbox Code Playgroud) 我需要显示自定义AlertDialog,但是只有在调用后没有更多片段时才显示NavController.navigateUp()。我当前的代码做了类似的事情,但是有一个错误:
override fun onBackPressed() {
if (navController.navigateUp()) {
return
}
showQuitDialog()
}
Run Code Online (Sandbox Code Playgroud)
这在某种程度上可行,但是如果我取消AlertDialog且不退出应用程序,则该应用程序navController已经导航到NavGraph根目录,而不是AlertDialog出现时所在的片段。因此,如果我尝试使用该片段中的任何导航操作,则会收到错误消息:
java.lang.IllegalArgumentException:此NavController未知导航目标com.example.test / actionNavigateToNextFragment
如果我可以访问中的mBackStack字段NavController,但是它是package private,并且我不能在当前项目中使用反射,则可以解决此问题。但是,如果是public,我将通过以下方式使用它:
override fun onBackPressed() {
// 2 because first one is NavGraph, second one is last fragment on the stack
if(navController.mBackStack.size > 2) {
navController.navigateUp()
return
}
showQuitDialog()
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点而无需反思?
android android-alertdialog kotlin android-navigation onbackpressed
我的项目中有以下架构:
MainActivity 布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="match_parent"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/my_nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
app:navGraph="@navigation/nav_graph"
app:defaultNavHost="true"
/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
nav_graph 设计:
nav_graph xml:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_graph"
app:startDestination="@id/loginFragment">
<fragment
android:id="@+id/loginFragment"
android:name="com.example.LoginFragment"
android:label="LoginFragment" >
<action
android:id="@+id/loginToContentAction"
app:destination="@id/contentFragment" />
</fragment>
<fragment
android:id="@+id/contentFragment"
android:name="com.example.ContentFragment"
android:label="ContentFragment" />
</navigation>
Run Code Online (Sandbox Code Playgroud)
在 中LoginFragment,我有以下逻辑:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if(presenter.isUserLogged()) {
// getNav() returns NavController from the MainActivity
getNav().navigateTo(R.id.loginToContentAction)
return
}
// init login views etc …Run Code Online (Sandbox Code Playgroud) android kotlin android-navigation android-architecture-navigation
我尝试备份我的大学项目数据库。我按照指示进行,似乎一切都输入了:
1:
2:
3:
在官方网站上,应该有类似此内容的另一种弹出消息:
但是我没有得到这个,也没有得到任何发生错误时显示的另一个。
我试图直接使用pg_dump.exe,但是它提示我输入密码。我尝试了所有密码-用户密码,服务器密码,这些密码用于PGAdmin 4中连接到数据库的密码,但其他密码似乎都不起作用。
我试图找到与此有关的任何信息,但是有关pg_dump.exe的所有文章都涉及如何自动执行密码输入。此备份静默失败的原因是什么?pg_dump.exe需要哪个密码?
如果需要的话,我会添加任何详细信息,我现在想算了4个小时...
我设法找出像 python 中那样的精确语法(检查容器中是否存在值),因此您可以检查值是否“在”任何支持begin()/end()方法的容器中。
这是我的实现:
#include <algorithm>
#include <iostream>
#include <vector>
template<class T>
struct specified {
specified(T const& value) : value_(value) {}
T value_;
template<class Container>
bool operator * (Container const& cont) {
return (std::find(cont.begin(), cont.end(), value_) != cont.end());
}
};
struct general {
template<class T>
friend specified<T> operator *(T const& rhs, general const&) {
return specified<T>(rhs);
}
};
#define in * general() *
int main() {
std::vector<int> vec{1,2,3};
std::cout << 1 in vec << std::endl;
std::cout …Run Code Online (Sandbox Code Playgroud) android ×5
kotlin ×5
c++ ×3
templates ×2
android-architecture-navigation ×1
c++11 ×1
drawable ×1
inheritance ×1
java ×1
pg-dump ×1
pgadmin ×1
pgadmin-4 ×1
postgresql ×1
python ×1
refactoring ×1
reference ×1
rename ×1
type-traits ×1
view ×1