小编you*_*uri的帖子

在android中双方四舍五入的进度条

我想在android中创建一个自定义进度条.我已经使用了以下xml文件(progress_bar_horizo​​ntal.xml):

<?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@android:id/background">
   <shape>
    <corners android:radius="8dip" />
    <stroke android:width="2dip" android:color="#FFFF"/>
    <solid android:color="#FFFF"/>              
   </shape>
  </item>
  <item android:id="@android:id/secondaryProgress">
   <clip>
    <shape>
     <corners android:radius="8dip" />
     <stroke android:width="2dip" android:color="#FFFF"/>
     <solid android:color="#FF00"/> 
    </shape>
   </clip>
  </item>
  <item android:id="@android:id/progress">
   <clip>
    <shape>
     <corners android:radius="8dip" />
     <stroke android:width="2dip" android:color="#FFFF"/>
     <solid android:color="#FF00"/> 
    </shape>
   </clip>
  </item>
 </layer-list>
Run Code Online (Sandbox Code Playgroud)

除了事实上我希望双方的进度条都有进展之外,一切都很有效.上述代码使得进度条在左侧被舍入并且简单地在右侧切割(不是圆形).这可能是因为剪辑标签.你能帮帮我吗?我应该改变什么才能在我的进度条中取得进展?

完整的布局如下:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">
  <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:background="@drawable/gradient_progress"
  android:padding="10dip"
  >
   <LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="horizontal"
   >
    <TextView
     android:id="@+id/progress_header"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textColor="#FF000000"
     android:textAppearance="?android:attr/textAppearanceMedium"
     android:textStyle="bold"
     android:text="Uploading" …
Run Code Online (Sandbox Code Playgroud)

user-interface android progress-bar

11
推荐指数
2
解决办法
2万
查看次数

在Windows下调试Android NDK

我正在将一个复杂的C应用程序移植到Android,作为一个SO库,用瘦java层包装.经过几个小时的麻烦,我在Android下编译代码,但当然,应用程序崩溃:(

环顾四周后,我明白在Android下调试C应用程序的唯一方法是通过gdb.既然我对gdb没有很多经验,那么任何人都可以分享一些见解吗?

任何人都有Windows下的gdb教程:)?

谢谢

android android-ndk

7
推荐指数
1
解决办法
1万
查看次数

完全使用本机代码从后台线程更新UI(没有JNI)?

我正在编写一个Android应用程序,它在后台线程中进行大量处理.使用C++在本机代码中执行计算.我想在计算过程中使用部分结果更新UI.

我能够通过JNI这样做,即在java中设置对UI对象的引用,然后通过JNI从本机代码调用此对象的方法.我正在寻找一个更有效的解决方案,在渲染部分没有任何JNI调用(基本设置和激活入口点必须在java中).

是否可以在不使用JNI的情况下完全使用本机代码将执行线程从后台更改为UI(仅在渲染部分中)?

谢谢你的回答.非常感激.

编辑: 我正在考虑使用OpenGL在我的视图中呈现计算内容(视频帧类型).在那种情况下,我可能想要使用eglSwapBuffers()从2.3开始的EGL库中可用的方法.我认为,最大的问题是如何在没有JNI开销的情况下轻松地从后台"计算"线程切换到本机代码中的UI"open GL"线程.你会推荐什么?谢谢你的帮助!

PSEUDOCODE: 这是一些伪代码,有助于说明我想在这里实现的目标.它更像是一个线程问题,但Android框架也会发挥作用.

// background thread
void Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz)
{
    //long calculation
    struct result * res = calculate();

    //want to update ui using opengl on ui thread
    updateGL(res);
}


//want to run it on ui thread as opengl can be run only on ui thread
void updateGL(struct result * res)
{
    //some opengl code with "res"
    someGLcodeWithResult(res);

    //render surface
    eglSwapBuffers();
}
Run Code Online (Sandbox Code Playgroud)

编辑2: 随着赏金缓慢逼近,再澄清一点.有几种方法可以调用updateGL上面的方法.最典型的是GLSurfaceView在java代码中使用.它需要设置一个渲染器(setRenderer()),然后用一些代码覆盖 …

c++ java-native-interface multithreading android android-ndk

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

如何合并两个具有相同代码但在不同结构上运行的类

我试图通过删除重复的代码来改进现有的C++代码,但无法提出令人信服的方法.来自更有经验的C++同事的任何见解都非常感谢.

所以我有两个结构定义,我无法控制:

struct struct_1
{
...
other_s * s1;
other_s * s2;
other_s * s3;
... //other fields
};

struct struct_2
{
...
other_s * s1;
other_s * s2;
other_s * s3;
... //other fields, different than struct_1, but not that important
};
Run Code Online (Sandbox Code Playgroud)

最后我要改进的代码.我有两个几乎相同的类,它们以相同的方式在相同名称的结构字段上操作,但字段来自不同的结构.这些类不对仅存在于一个结构中的结构字段进行操作.这里(简化):

class class_1
{
    struct_1 * s;

    class_1(){
        s = new struct_1(); //the only practical difference
        ...
    }

    void method()
    {
        ...

        //this is simplification, in reality the code is more complex
        //however the same as in …
Run Code Online (Sandbox Code Playgroud)

c++ refactoring design-patterns code-duplication

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