为什么C的printf格式字符串有%c和%s?
我知道它%c代表一个单个字符并%s表示一个以空字符结尾的字符串,但单独的字符串表示不足够吗?
我刚开始使用Kotlin试用Android应用.我只想继承这样的Application类:
class SomeApp : Application {
}
Run Code Online (Sandbox Code Playgroud)
但是编译器提出了警告:
并建议将其更改为:
class SomeApp : Application() {
override fun onCreate() {
super.onCreate()
}
}
Run Code Online (Sandbox Code Playgroud)
我在文档中读到了主要和辅助构造函数.所以如果超类有一个主构造函数,那么有必要在这里写吗?像Application类有自己的构造函数
public Application() {
super(null);
}
Run Code Online (Sandbox Code Playgroud)
然后有必要有派生的主要构造函数?或者我不能像Java那样做:
class SomeApp : Application {
constructor SomeApp(){
super();
}
}
Run Code Online (Sandbox Code Playgroud)
或者这个错误暗示了其他什么?任何人都可以详细解释我吗?我对这门语言很陌生,这对我来说很奇怪.
编辑:在java中我可以执行以下操作: class SomeApp extends Application{ }
它有隐式构造,所以我没有写:class SomeApp extends Application{ public Application(){ super(); } }但在科特林我必须定义像下面空的构造:
class SomeApp:Application(){ }
?
我正在学习在Android中创建导航抽屉.阅读本文时,我无法理解以下代码:
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
Run Code Online (Sandbox Code Playgroud)
文件说:
将抽屉指示符/示能表的状态与链接的DrawerLayout同步.
这应该从您的Activity的onPostCreate方法调用,以便在DrawerLayout的实例状态恢复后进行同步,以及状态可能以不通知ActionBarDrawerToggle的方式分散的任何其他时间.(例如,如果您停止转发适当的抽屉事件一段时间.)
而且我读到onPostCreate()从sstn的答案在这里:OnPostCreate在片段
onPostCreate()主要用于框架使用(尽管你可以覆盖它).文档说它是在onStart()和onRestoreInstanceState()之后调用的.
这可能导致假设它可能在onResume()之前被调用,因此可能在消息循环调度事件之前(包括AsyncTask的onPostExecute()方法),这意味着你的onPostExecute()只会在onPause()之后触发.
由于onPostCreate()没有正确记录,并且不是真正用于应用程序 - 我可能想说依赖任何观察到的行为并不是一个好主意.
从这两个我无法理解.究竟做syncState()了什么以及为什么它应该在里面onPostcreate()?谁能更好地解释一下?
java android android-layout android-activity navigation-drawer
我正在学习Kotlin.我的代码如下:
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
decoupler.attachNotifier(this)
if(activity is ScreenRouter) {
decoupler.attachRouter(activity)
}
}
Run Code Online (Sandbox Code Playgroud)
attachRouter() 方法:
fun attachRouter(router: ScreenRouter?) {
this.router = router
}
Run Code Online (Sandbox Code Playgroud)
如文档中所述,kotlin在使用is运算符检查后自动转换为类型.所以,我希望它会起作用.但相反,它困扰我编译错误说:
Smartcast ScreenRouter是不可能的,因为它activity是一个开放或定制的吸气剂.
我想也许错误是因为活动可以为空,所以我试过:
if(activity!=null && activity is ScreenRouter) {
decoupler.attachRouter(activity)
}
Run Code Online (Sandbox Code Playgroud)
但它没有工作,编译失败同样的错误.
但是,以下代码工作正常:
if(activity is ScreenRouter) {
decoupler.attachRouter(activity as ScreenRouter)
}
Run Code Online (Sandbox Code Playgroud)
它没关系,但上面的错误似乎没有解释为什么smartcast失败.我不是Kotlin专家,我只是一个学习Kotlin的初学者.我找不到任何文件.这些错误描述使Kotlin难以学习.任何人都可以简单地解释一下吗
我正在尝试设置Android Studio + LiquidFun.我遵循了很多这样的教程:http : //www.shaneenishry.com/blog/2014/08/17/ndk-with-android-studio/ http://tools.android.com/tech-docs/android -ndk-preview 但要么不全面,要么不起作用.我尝试了所有,直接将文件(C++)复制到我的项目,尝试使用NDK导入,尝试使用gradle修复NDK等.但没有任何作用.如果有人能帮助我解决我的问题或正确安装Liquidfun,我太过分了.谢谢.
我需要创建一个垂直的Recyclerview,其中应调整屏幕中心的项目视图,以便在滚动时具有缩放效果.
我尝试但没有奏效的事情:
添加滚动侦听器并按位置循环浏览项目视图,测量居中位置,然后更新LayoutParams居中view.
RecyclerView在滚动时不会计算项目的位置或更新视图.IllegalStateException如果执行此类操作,则抛出onScrolledLayoutParams在onScrollStateChanged滚动状态下更改居中的项目视图是IDLE或SETTLING.
最后的选择仍然是实现自己的自定义LayoutManager,将扩展默认LayoutManager.
Layoutmanager涉及处理需要处理的更复杂的计算.任何其他解决方案或想法将不胜感激.
java performance android android-layout android-recyclerview
我正在关注覆盖行动栏的官方开发人员指南.
我style.xml的如下:
<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="actionBarStyle">@style/CustomActionBarTheme</item>
</style>
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的midSdkVersion是14,预期输出与官方指南相似:
.
相反,在我的情况下,输出是: 
(我已将背景颜色设置为活动...但它不会覆盖操作栏.)
如果我做的任何事都错了,请帮助我.
我想在airnb和许多其他应用程序中使用类似的动作栏.任何人都可以给我完整的答案吗?

我有以下布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<TextView
android:id="@+id/tvErrorTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="@android:color/background_dark"
android:textSize="18sp"
/>
<TextView
android:id="@+id/tvErrorDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textColor="@android:color/darker_gray"
android:textSize="16sp"
/>
<TextView
android:id="@+id/tvAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="10dp"
android:layout_gravity="end"
android:padding="5dp"
android:textSize="15sp"
android:textStyle="bold"
android:textAllCaps="true"
android:textColor="@android:color/holo_purple"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当我想在下面的活动之外使用kotlin android扩展时,它不起作用.我最终做了findViewById.
...
...
import kotlinx.android.synthetic.main.dialog_error.*
...
...
val view = LayoutInflater.from(context).inflate(R.layout.dialog_error, null, false)
val tvErrorTitle = view.findViewById(R.id.tvErrorTitle) as TextView
val tvErrorDesc = view.findViewById(R.id.tvErrorDesc) as TextView
val tvErrorAction = view.findViewById(R.id.tvAction) as TextView
Run Code Online (Sandbox Code Playgroud)
它不直接从xml中提取视图.如何在programetically inflated布局中使用它并避免findViewById …
android ×8
java ×3
kotlin ×3
android-ndk ×1
c ×1
casting ×1
constructor ×1
game-engine ×1
liquidfun ×1
performance ×1
types ×1