我在Kotlin中遇到了这个错误:
class GitHubRepoAdapter(private val context: Context,
private val values: List<GithubRepo>) : ArrayAdapter<GithubRepo>(context, R.layout.list_item,
values) {
Run Code Online (Sandbox Code Playgroud)
私有val上下文:上下文
在日志中它说:
错误:(14,25)意外覆盖:以下声明具有相同的JVM签名(getContext()Landroid/content/Context;):fun():Context fun getContext():Context!
我无法看到导致问题的原因.
我只是想为MongoDB尝试MongoDB Compass GUI,但是当我尝试使用本地主机端口连接时:27017我收到此错误:
无法在提供的主机和端口上连接到MongoDB
我在YouTube上按照这些说明操作.
我正在尝试将我的设备ID提供给Logcat,但Android Studio正在向我发出此警告.
建议不要使用getstring来获取设备标识符
String deviceID = Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
Run Code Online (Sandbox Code Playgroud)
为什么不推荐?
我想在 Jetpack Compose 中将屏幕水平分成两半,如下所示:

@Composable
fun Splash(alpha: Float) {
val configuration = LocalConfiguration.current
val screenHeight = configuration.screenHeightDp.dp
val screenWidth = configuration.screenWidthDp.dp
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.cat2))
Box(
modifier = Modifier
.background(Blue)
.height(screenHeight / 2)
.padding(8.dp),
contentAlignment = Alignment.TopCenter
) {
Column() {
Text(text = "Example", fontSize = 44.sp)
}
}
Box(
modifier = Modifier
.background(Red)
.height(screenHeight / 2)
.padding(8.dp),
contentAlignment = Alignment.BottomCenter
){
Column {
Text(text = "Example", textAlign = TextAlign.End, color = Grey, fontSize = 12.sp)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我可以使用 …
我一直在Android Studio中开展一个项目,它有很多评论.是否可以删除代码中的所有注释(单行//和多行/*)?优选地,不处理正则表达式.
我有一个水平的recyclerView,当我第一次打开活动时,我想让recyclerview中的所有项目滚动到底部(在这种情况下向右)并返回到顶部(向左).有点像动画.滚动行为应该对用户可见.
我试着这样做:
Animation slideRight = AnimationUtils.loadAnimation(this, R.anim.slide_right);
Animation slideLeft = AnimationUtils.loadAnimation(this, R.anim.slide_left);
slideRight.setDuration(1000);
slideLeft.setDuration(1000);
slideRight.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
recyclerView.startAnimation(slideLeft);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
recyclerView.startAnimation(slideRight);
Run Code Online (Sandbox Code Playgroud)
anim slide left:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="200"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
Run Code Online (Sandbox Code Playgroud)
向右滑动:
<translate
android:duration="200"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
Run Code Online (Sandbox Code Playgroud)
它可以工作,但它只是将recyclerview作为一个整体滑动,我只想滚动(滑动)项目.我怎样才能做到这一点?
我明白了
为了在进程中运行 dex,Gradle 守护进程需要更大的堆。
错误,我想添加org.gradle.jvmargs=-Xmx5120M到我的 gradle.properties 来解决这个问题。但是,我在我的项目中找不到该gradle.properties文件。
这个问题可能听起来很简单,但我很难过.
我可以通过这种方式进行改造2:
class RetrofitClient {
private static Retrofit retrofit = null;
static Retrofit getClient(String baseUrl) {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
Run Code Online (Sandbox Code Playgroud)
Api服务界面:
@POST("postsInit")
@FormUrlEncoded
Call<InitPost> postInit(
@Field("appVersion") String versionName,
@Field("appId") String applicationId,
);
Run Code Online (Sandbox Code Playgroud)
最后:
apiService.postInit(versionName, applicationId).enqueue(new Callback<InitPost>() {
@Override
public void onResponse(@NonNull Call<InitPost> call, @NonNull Response<InitPost> response) {
if (response.isSuccessful()) {
Timber.d("post submitted to API");
getInitResponse();
}
}
@Override
public void onFailure(@NonNull Call<InitPost> call, @NonNull Throwable t) …Run Code Online (Sandbox Code Playgroud) 我使用水平 recyclerview 作为自定义底部导航栏。我想为每个项目定义一个按下状态,以便它们的颜色可以改变。
我试图这样做,但无法管理它
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/menu_pressed" android:state_activated="true" />
<item android:drawable="@color/menu_pressed" android:state_pressed="true" />
<item android:drawable="@color/menu_pressed" android:state_checked="true" />
<item android:drawable="@color/menu_pressed" android:state_focused="true" />
<item android:drawable="@color/menu" />
</selector>
Run Code Online (Sandbox Code Playgroud)
回收者观点:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_gravity="bottom"
android:background="@drawable/menu_selector"
android:fadingEdge="vertical|horizontal"
android:fadingEdgeLength="60dp"
android:fillViewport="false"
android:requiresFadingEdge="horizontal|vertical"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true">
Run Code Online (Sandbox Code Playgroud) 之后我收到了这个警告gradle build.我认为这与我Proguard rules和我有关Logs.我怎样才能"删除无效的当地人信息"?
我想将我的Log包装到LogUtil类:
public class LogUtils {
public static void debug(final String tag, String message) {
if (BuildConfig.DEBUG) {
Log.d(tag, message);
}
}
}
Run Code Online (Sandbox Code Playgroud)
并将其添加到proguard规则
-assumenosideeffects class android.util.Log {
public static *** d(...);
}
Run Code Online (Sandbox Code Playgroud)
是一个很好的解决方案,但我的项目中有很多Log.d,所以这很难.
与木材相同的问题.我认为转换为时已晚
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}
Run Code Online (Sandbox Code Playgroud)