小编Viv*_*hra的帖子

如何将在纯 python 中动态创建的按钮添加到用 Kivy 语言编写的 kivy 布局?

我的问题是我需要根据可变数量的网格方块创建一个按钮网格,并将它们放置在网格布局上并使用屏幕管理器将它们显示在屏幕上。我知道如何使用简单的 for 循环在纯 python 中做到这一点,但是我用 kivy 语言为我的程序编写了布局,我不知道如何将按钮添加到网格布局中,因为我不知道如何在 kv 文件中正确引用它们。相关的python代码是:

def buildMap():
    index = 0
    for index in range(0, numberOfGridBlocks):
        mainMap.ids["Map"].add_widget(Button())
        index = index + 1
buildMap() 
Run Code Online (Sandbox Code Playgroud)

kv文件的相关部分是:

ScreenManagement:
    MainMenuScreen:
    NewGameMenuScreen:
    JoinGameMenuScreen:
    TutorialMenuScreen:
    SettingsMenuScreen:
    MapScreen:

<MenuButton>:
    on_press: app.menuButtonPressed()
    size_hint_y: .125
    background_normal: "images/button.png"
    background_down: "images/buttonPressed.png"

<Button>:

<BoxLayout>:
    orientation: "vertical"
<MapLayout>:

<MapScreen>:
    name: "mapScreen"
    MapLayout:
        id: "Map"
        cols: 5
Run Code Online (Sandbox Code Playgroud)

python kivy

5
推荐指数
1
解决办法
7239
查看次数

错误:(3,0)原因:org/apache/commons/lang3/StringUtils

我收到以下错误

错误:(3,0)原因:org/apache/commons/lang3/StringUtils

当我尝试在我的Android项目中添加数据绑定时.

我的依赖包括:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha7'
        classpath 'me.tatarka:gradle-retrolambda:3.2.2'
        classpath 'com.android.databinding:dataBinder:1.0-rc1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

我的gradle包装器是:distributionUrl = https://services.gradle.org/distributions/gradle-2.2.1-all.zip

我的gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.android.databinding'

android …
Run Code Online (Sandbox Code Playgroud)

data-binding android gradle

5
推荐指数
1
解决办法
2676
查看次数

在tablayout中将颜色设置为未选中的制表符指示符

我正在使用谷歌提供的tablayout,除了未选择的标签指示器的颜色外,一切正常.我无法设置未选中的标签指示颜色.

 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <android.support.design.widget.AppBarLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

     <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
         android:layout_width="match_parent"
         android:layout_height="?attr/actionBarSize"
         android:background="?attr/colorPrimary"
         app:layout_scrollFlags="scroll|enterAlways"
         app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

     <android.support.design.widget.TabLayout
         android:id="@+id/tabs"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:tabMode="fixed"
         style="@style/MyCustomTabLayout"

         />
 </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.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
4
解决办法
6484
查看次数

音乐播放器要求写入外部存储许可?

我正在Android中创建一个音乐播放器应用程序.它工作正常但每当我滚动歌曲列表时它开始崩溃并给出这个例外

Process: com.example.lenovo.musicplayer, PID: 31100
java.lang.SecurityException: External path: /storage/emulated/0/Android/data/com.android.providers.media/albumthumbs/1460104607336: Neither user 10294 nor current process has android.permission.WRITE_EXTERNAL_STORAGE.      
at android.os.Parcel.readException(Parcel.java:1555)      
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:153)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:691)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1170)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:994)
at android.content.ContentResolver.openInputStream(ContentResolver.java:719)
at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:1110)
at com.example.lenovo.musicplayer.Adapter.getView(Adapter.java:119)
at android.widget.AbsListView.obtainView(AbsListView.java:2571)
at android.widget.ListView.makeAndAddView(ListView.java:1894)
at android.widget.ListView.fillDown(ListView.java:710)
at android.widget.ListView.fillGap(ListView.java:674)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5900)
at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:5378)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:825)
at android.view.Choreographer.doCallbacks(Choreographer.java:619)
at android.view.Choreographer.doFrame(Choreographer.java:578)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:811)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6102)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Run Code Online (Sandbox Code Playgroud)

当我在清单文件中提供写入权限时,这个问题就消失了,但是我不明白的是为什么WriteExternalStoragePermission当我没有向任何类型的存储写入任何内容时它会要求它.据我所知,音乐播放器不需要写入外部存储权限.

这是歌曲列表活动的代码

   public class ActivitySongsList …
Run Code Online (Sandbox Code Playgroud)

android android-mediaplayer android-permissions android-securityexception

5
推荐指数
1
解决办法
1134
查看次数

SnackBar 导致 ScrollView 崩溃并出现非法状态异常

我正在开发一个应用程序,其中我有一个用 ScrollView 包装的布局。在此布局的片段中,我正在使用 Web 服务从服务器获取数据并将其显示在我的布局中。每当 Web 服务中出现错误或没有可用数据时,我都会向用户显示一个带有相应消息的快捷栏。

问题

我遇到了一个很少发生的问题。当有时数据不可用并显示小吃栏时,我的应用程序崩溃并显示消息的非法状态异常

ScrollView can host only one direct child

这是崩溃日志

java.lang.IllegalStateException: ScrollView can host only one direct child
                                             at android.widget.ScrollView.addView(ScrollView.java:253)
                                             at android.support.design.widget.Snackbar.showView(Snackbar.java:475)
                                             at android.support.design.widget.Snackbar$1.handleMessage(Snackbar.java:162)
                                             at android.os.Handler.dispatchMessage(Handler.java:107)
                                             at android.os.Looper.loop(Looper.java:214)
                                             at android.app.ActivityThread.main(ActivityThread.java:6102)
                                             at java.lang.reflect.Method.invoke(Native Method)
                                             at java.lang.reflect.Method.invoke(Method.java:372)
                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Run Code Online (Sandbox Code Playgroud)

我在许多屏幕中使用这种组合,所以我只发布其中一个 xml 的布局代码

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none">

    <LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background"
        android:orientation="vertical"
        android:paddingBottom="20dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="10dp">

        <com.xsinfosol.emergency.progressbar.RopeProgressBar
            android:id="@+id/progress_bar1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:ropeDynamicLayout="true"
            app:ropePrimaryColor="@color/red"
            app:ropeSecondaryColor="#20FFFFFF"
            app:ropeSlack="0dp"
            app:ropeStrokeWidth="10dp" />

        <ImageView …
Run Code Online (Sandbox Code Playgroud)

android scrollview illegalstateexception android-snackbar

5
推荐指数
2
解决办法
1790
查看次数

robolectric 不支持在 sqlite 中批量插入

我用下面的代码进行了junit测试

@RunWith(RobolectricTestRunner.class)

 public class AccountDAOTest {

}
Run Code Online (Sandbox Code Playgroud)

在我的DadatabaseHelper下面的查询中执行

 public static final String INIT_DATA = "insert into STATE(STATEID, STATENAME, STATECODE) VALUES\n" +
                "(1, 'Jammu and Kashmir', 'JK'),\n" +
                "(2, 'Himachal Pradesh', 'HP')"
  sqlitedatabase.execSQL(INIT_DATA);
Run Code Online (Sandbox Code Playgroud)

上面的代码在模拟器/Android手机上运行。但是当我运行 junit 作为测试时,它失败并抛出以下错误。

android.database.sqlite.SQLiteException: Cannot prepare statement, base error code: 1

at org.robolectric.shadows.ShadowSQLiteConnection.rethrow(ShadowSQLiteConnection.java:56)
at org.robolectric.shadows.ShadowSQLiteConnection.access$500(ShadowSQLiteConnection.java:33)
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.execute(ShadowSQLiteConnection.java:466)
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.prepareStatement(ShadowSQLiteConnection.java:376)
at org.robolectric.shadows.ShadowSQLiteConnection.nativePrepareStatement(ShadowSQLiteConnection.java:67)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.__constructor__(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
at com.bizega.bondacc.database.DatabaseHelper.onCreate(DatabaseHelper.java:145)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at …
Run Code Online (Sandbox Code Playgroud)

mysql sqlite junit android robolectric

5
推荐指数
0
解决办法
231
查看次数

找到二进制字符串中包含相等数量0和1的最大子字符串

最近在一次采访中,我被要求编写一个程序来查找最大的子字符串,其中包含二进制字符串中相同数量的0s和1s.

例如:

如果给定的字符串是1010111输出将1010包含2 0秒和2 1秒.

我尝试了很多,但无论如何都无法想出为这个东西构建算法.

有人可以让我先想知道如何继续或者使用什么数据结构来解决这个问题?

language-agnostic algorithm

4
推荐指数
1
解决办法
497
查看次数

尝试添加深层链接我的Android应用程序

我的应用程序运行正常,但每当我在我的清单中添加深层链接代码时,我的应用程序午餐图标消失,这是我的清单文件

<activity
            android:name=".login.LoginActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="https" />
                <data android:host="gizbo.ae" />
            </intent-filter>
        </activity> 
Run Code Online (Sandbox Code Playgroud)

什么时候我添加这三行深度链接.应用程序图标启动图标从设备中消失.

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https" />
<data android:host="gizbo.ae" />
Run Code Online (Sandbox Code Playgroud)

即使我删除了这两行

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"/> 
Run Code Online (Sandbox Code Playgroud)

同样的问题.

我只是想让我的应用在谷歌搜索中可见,我正在关注此链接

android deep-linking

3
推荐指数
1
解决办法
1639
查看次数

videoview右侧白色空间

我无法删除我的视频预览的空白区域我已经添加了所有的alignparent但仍然无法正常工作.它的来源是来自服务器.视频中没有空格.

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context="com.extras.PermitVideoFrag">

    <VideoView
        android:id="@+id/vid_permit"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerHorizontal="true" 
       />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我现在真的很沮丧.我找不到一个体面的答案.

android android-videoview

3
推荐指数
1
解决办法
978
查看次数

如何在自定义通知文本视图中设置值

请帮助我在自定义通知中的 textview 中设置文本

    private void startNotification()
 {
     String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
    Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
    RemoteViews notificationView = new RemoteViews(getPackageName(),R.layout.mynotification);
    mRemoteViews.setTextViewText(R.id.appName, getResources().getText(0,"gfhf"));
    mBuilder.setContent(mRemoteViews);
    Intent notificationIntent = new Intent(this, FlashLight.class);
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.contentView = notificationView;
    notification.contentIntent = pendingNotificationIntent;
    notification.flags |= Notification.FLAG_NO_CLEAR;
    Intent switchIntent = new Intent(this, switchButtonListener.class);
    PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, switchIntent, 0);
    notificationView.setOnClickPendingIntent(R.id.closeOnFlash,  pendingSwitchIntent);
    notificationManager.notify(1, notification);

}
Run Code Online (Sandbox Code Playgroud)

java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“void android.widget.RemoteViews.setTextViewText(int, java.lang.CharSequence)”

请帮我解决这个问题。如何在android中的通知中设置textview的值,提前致谢。

sdk android android-notifications

2
推荐指数
1
解决办法
2659
查看次数

在TextInputLayout中使用"android:hintAnimationEnabled"有什么用?

1. 什么android:hintAnimationEnabled用于TextInputLayout

2. android:hintAnimationEnabled和之间的区别是android:hintEnabled什么?

android android-textinputlayout

2
推荐指数
1
解决办法
1105
查看次数

Android studio 2.2.3启动时速度太慢

Android工作室启动时速度太慢.在加载弹出之前需要等待几分钟.我不是在谈论gradle构建,而是android本身......这不是我的第一个android工作室......在我格式化笔记本电脑之前我也使用了android studio(也许是2.2.1或2.2.0),因此我知道需要多少时间来显示加载屏幕.

有关详细信息,我使用的是第6代I5 cpu,8GB Ram和ssd.

android android-studio-2.2

0
推荐指数
1
解决办法
4227
查看次数

如何在心形drawable xml中添加边框(描边)线

  • 如下我绘制可绘制的 xml 像心形
  • 但我想添加边框线,如(描边)
  • 我遇到一些困难如何添加该行

    <path
        android:fillColor="#a39f9f"
        android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z"/>
    
    Run Code Online (Sandbox Code Playgroud)

xml android android-shape android-vectordrawable

0
推荐指数
1
解决办法
1847
查看次数