小编Kel*_*Tan的帖子

设置relativelayout的宽度为屏幕宽度的1/3?

我有一个如下的布局.现在,我不想将相对布局的宽度设置为固定240 dp.我想将相对布局的宽度设置为屏幕宽度的1/3.是否可以在xml文件中执行此操作.如果不可能,我怎么能用java代码实现呢?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/fullscreen"
        style="@style/translucent">
           <RelativeLayout
            android:layout_width="240dp"
            android:layout_height="fill_parent"
            android:layout_gravity="right"
            android:gravity="center"
            android:background="#88000000"
            android:id="@+id/sidebar">

           </RelativeLayout>

    </FrameLayout>
Run Code Online (Sandbox Code Playgroud)

android width android-layout android-relativelayout

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

C++ pthread,两个线程读取一个全局变量

如果有两个线程只读取全局变量,是否有必要使用互斥锁来锁定和解锁全局变量?

c++ mutex pthreads

8
推荐指数
3
解决办法
8455
查看次数

如何使用 ffmpeg C++ 获取当前帧号

通常,我在解码视频时使用以下代码来获取当前帧号。

while(av_read_frame(pFormatCtx, &packet)>=0) {
    if(packet.stream_index==videoStream) {
      // Decode video frame
      avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);

      // Did we get a video frame?
      if(frameFinished) {
    int currentFrameNumber = pFrame->coded_picture_number; 
    }
    /* Free the packet that was allocated by av_read_frame*/
    av_free_packet(&packet);
  }
Run Code Online (Sandbox Code Playgroud)

然后,当我实现查找功能时,我添加 av_seek_frame 来查找所需的位置,如下所示:

if(av_seek_frame(pFormatCtx, -1, seekTarget, 0 )<0){
         LOG("log","error when seeking");
}
while(av_read_frame(pFormatCtx, &packet)>=0) {
        if(packet.stream_index==videoStream) {
          // Decode video frame
          avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);

          // Did we get a video frame?
          if(frameFinished) {
        int currentFrameNumber = pFrame->coded_picture_number; 
        }
        /* Free …
Run Code Online (Sandbox Code Playgroud)

c++ ffmpeg decode frame

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

Django相当于rails respond_to

在Rails中,我可以使用respond_to来定义控制器如何根据请求格式进行响应.

在routes.rb中

 map.connect '/profile/:action.:format', :controller => "profile_controller" 
Run Code Online (Sandbox Code Playgroud)

在profile_controller.rb中

def profile
      @profile = ...
      respond_to do |format|
        format.html {  }
        format.json {  }

      end
end
Run Code Online (Sandbox Code Playgroud)

目前,在Django中,我必须使用两个URL和两个动作:一个返回html,一个返回json.

url.py:

urlpatterns = [
    url(r'^profile_html', views.profile_html),
    url(r'^profile_json', views.profile_json),
]
Run Code Online (Sandbox Code Playgroud)

view.py

def profile_html (request):

   #some logic calculations

   return render(request, 'profile.html', {'data': profile})

def profile_json(request):

  #some logic calculations

  serializer = ProfileSerializer(profile)

  return Response(serializer.data)
Run Code Online (Sandbox Code Playgroud)

使用这种方法,逻辑代码变得重复.当然,我可以定义一个方法来进行逻辑计算,但代码直到详细.

在Django还有,我可以将它们组合在一起吗?

django json ruby-on-rails equivalent respond-to

4
推荐指数
2
解决办法
68
查看次数

C++读取wav文件,subchunk1size = 18

通常 wav 文件的 subchunk1size 是 16。但是,我有一些 subchunk1size = 18 的 wav 文件。我有 C++ 代码来读取 subchunk1size = 16 的 wav 文件。现在我想读取 subchunk1size = 18 的 wav 文件。任何帮助,将不胜感激。

typedef struct header_file
{
    char chunk_id[4];
    int chunk_size;
    char format[4];
    char subchunk1_id[4];
    int subchunk1_size;
    short int audio_format;
    short int num_channels;
    int sample_rate;            
    int byte_rate;
    short int block_align;
    short int bits_per_sample;
    char subchunk2_id[4];
    int subchunk2_size;         
} header;
Run Code Online (Sandbox Code Playgroud)

上面是我的代码中的struct header_file,用于读取subchunk1size = 16的wav文件。

c++ header wav

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